
_grep:     file format elf32-i386


Disassembly of section .text:

00000000 <grep>:
char buf[1024];
int match(char*, char*);

void
grep(char *pattern, int fd)
{
       0:	55                   	push   %ebp
       1:	89 e5                	mov    %esp,%ebp
       3:	83 ec 28             	sub    $0x28,%esp
  int n, m;
  char *p, *q;
  
  m = 0;
       6:	c7 45 f4 00 00 00 00 	movl   $0x0,-0xc(%ebp)
  while((n = read(fd, buf+m, sizeof(buf)-m)) > 0){
       d:	e9 bf 00 00 00       	jmp    d1 <grep+0xd1>
    m += n;
      12:	8b 45 ec             	mov    -0x14(%ebp),%eax
      15:	01 45 f4             	add    %eax,-0xc(%ebp)
    p = buf;
      18:	c7 45 f0 20 17 00 00 	movl   $0x1720,-0x10(%ebp)
    while((q = strchr(p, '\n')) != 0){
      1f:	eb 53                	jmp    74 <grep+0x74>
      *q = 0;
      21:	8b 45 e8             	mov    -0x18(%ebp),%eax
      24:	c6 00 00             	movb   $0x0,(%eax)
      if(match(pattern, p)){
      27:	8b 45 f0             	mov    -0x10(%ebp),%eax
      2a:	89 44 24 04          	mov    %eax,0x4(%esp)
      2e:	8b 45 08             	mov    0x8(%ebp),%eax
      31:	89 04 24             	mov    %eax,(%esp)
      34:	e8 c2 01 00 00       	call   1fb <match>
      39:	85 c0                	test   %eax,%eax
      3b:	74 2e                	je     6b <grep+0x6b>
        *q = '\n';
      3d:	8b 45 e8             	mov    -0x18(%ebp),%eax
      40:	c6 00 0a             	movb   $0xa,(%eax)
        write(1, p, q+1 - p);
      43:	8b 45 e8             	mov    -0x18(%ebp),%eax
      46:	83 c0 01             	add    $0x1,%eax
      49:	89 c2                	mov    %eax,%edx
      4b:	8b 45 f0             	mov    -0x10(%ebp),%eax
      4e:	89 d1                	mov    %edx,%ecx
      50:	29 c1                	sub    %eax,%ecx
      52:	89 c8                	mov    %ecx,%eax
      54:	89 44 24 08          	mov    %eax,0x8(%esp)
      58:	8b 45 f0             	mov    -0x10(%ebp),%eax
      5b:	89 44 24 04          	mov    %eax,0x4(%esp)
      5f:	c7 04 24 01 00 00 00 	movl   $0x1,(%esp)
      66:	e8 81 05 00 00       	call   5ec <write>
      }
      p = q+1;
      6b:	8b 45 e8             	mov    -0x18(%ebp),%eax
      6e:	83 c0 01             	add    $0x1,%eax
      71:	89 45 f0             	mov    %eax,-0x10(%ebp)
  
  m = 0;
  while((n = read(fd, buf+m, sizeof(buf)-m)) > 0){
    m += n;
    p = buf;
    while((q = strchr(p, '\n')) != 0){
      74:	c7 44 24 04 0a 00 00 	movl   $0xa,0x4(%esp)
      7b:	00 
      7c:	8b 45 f0             	mov    -0x10(%ebp),%eax
      7f:	89 04 24             	mov    %eax,(%esp)
      82:	e8 c2 03 00 00       	call   449 <strchr>
      87:	89 45 e8             	mov    %eax,-0x18(%ebp)
      8a:	83 7d e8 00          	cmpl   $0x0,-0x18(%ebp)
      8e:	75 91                	jne    21 <grep+0x21>
        *q = '\n';
        write(1, p, q+1 - p);
      }
      p = q+1;
    }
    if(p == buf)
      90:	81 7d f0 20 17 00 00 	cmpl   $0x1720,-0x10(%ebp)
      97:	75 07                	jne    a0 <grep+0xa0>
      m = 0;
      99:	c7 45 f4 00 00 00 00 	movl   $0x0,-0xc(%ebp)
    if(m > 0){
      a0:	83 7d f4 00          	cmpl   $0x0,-0xc(%ebp)
      a4:	7e 2b                	jle    d1 <grep+0xd1>
      m -= p - buf;
      a6:	ba 20 17 00 00       	mov    $0x1720,%edx
      ab:	8b 45 f0             	mov    -0x10(%ebp),%eax
      ae:	89 d1                	mov    %edx,%ecx
      b0:	29 c1                	sub    %eax,%ecx
      b2:	89 c8                	mov    %ecx,%eax
      b4:	01 45 f4             	add    %eax,-0xc(%ebp)
      memmove(buf, p, m);
      b7:	8b 45 f4             	mov    -0xc(%ebp),%eax
      ba:	89 44 24 08          	mov    %eax,0x8(%esp)
      be:	8b 45 f0             	mov    -0x10(%ebp),%eax
      c1:	89 44 24 04          	mov    %eax,0x4(%esp)
      c5:	c7 04 24 20 17 00 00 	movl   $0x1720,(%esp)
      cc:	e8 b7 04 00 00       	call   588 <memmove>
{
  int n, m;
  char *p, *q;
  
  m = 0;
  while((n = read(fd, buf+m, sizeof(buf)-m)) > 0){
      d1:	8b 45 f4             	mov    -0xc(%ebp),%eax
      d4:	ba 00 04 00 00       	mov    $0x400,%edx
      d9:	89 d1                	mov    %edx,%ecx
      db:	29 c1                	sub    %eax,%ecx
      dd:	89 c8                	mov    %ecx,%eax
      df:	8b 55 f4             	mov    -0xc(%ebp),%edx
      e2:	81 c2 20 17 00 00    	add    $0x1720,%edx
      e8:	89 44 24 08          	mov    %eax,0x8(%esp)
      ec:	89 54 24 04          	mov    %edx,0x4(%esp)
      f0:	8b 45 0c             	mov    0xc(%ebp),%eax
      f3:	89 04 24             	mov    %eax,(%esp)
      f6:	e8 e9 04 00 00       	call   5e4 <read>
      fb:	89 45 ec             	mov    %eax,-0x14(%ebp)
      fe:	83 7d ec 00          	cmpl   $0x0,-0x14(%ebp)
     102:	0f 8f 0a ff ff ff    	jg     12 <grep+0x12>
    if(m > 0){
      m -= p - buf;
      memmove(buf, p, m);
    }
  }
}
     108:	c9                   	leave  
     109:	c3                   	ret    

0000010a <main>:

int
main(int argc, char *argv[])
{
     10a:	55                   	push   %ebp
     10b:	89 e5                	mov    %esp,%ebp
     10d:	83 e4 f0             	and    $0xfffffff0,%esp
     110:	83 ec 20             	sub    $0x20,%esp
  int fd, i;
  char *pattern;
  
  if(argc <= 1){
     113:	83 7d 08 01          	cmpl   $0x1,0x8(%ebp)
     117:	7f 19                	jg     132 <main+0x28>
    printf(2, "usage: grep pattern [file ...]\n");
     119:	c7 44 24 04 bc 11 00 	movl   $0x11bc,0x4(%esp)
     120:	00 
     121:	c7 04 24 02 00 00 00 	movl   $0x2,(%esp)
     128:	e8 3c 06 00 00       	call   769 <printf>
    exit();
     12d:	e8 9a 04 00 00       	call   5cc <exit>
  }
  pattern = argv[1];
     132:	8b 45 0c             	mov    0xc(%ebp),%eax
     135:	8b 40 04             	mov    0x4(%eax),%eax
     138:	89 44 24 18          	mov    %eax,0x18(%esp)
  
  if(argc <= 2){
     13c:	83 7d 08 02          	cmpl   $0x2,0x8(%ebp)
     140:	7f 19                	jg     15b <main+0x51>
    grep(pattern, 0);
     142:	c7 44 24 04 00 00 00 	movl   $0x0,0x4(%esp)
     149:	00 
     14a:	8b 44 24 18          	mov    0x18(%esp),%eax
     14e:	89 04 24             	mov    %eax,(%esp)
     151:	e8 aa fe ff ff       	call   0 <grep>
    exit();
     156:	e8 71 04 00 00       	call   5cc <exit>
  }

  for(i = 2; i < argc; i++){
     15b:	c7 44 24 1c 02 00 00 	movl   $0x2,0x1c(%esp)
     162:	00 
     163:	e9 81 00 00 00       	jmp    1e9 <main+0xdf>
    if((fd = open(argv[i], 0)) < 0){
     168:	8b 44 24 1c          	mov    0x1c(%esp),%eax
     16c:	8d 14 85 00 00 00 00 	lea    0x0(,%eax,4),%edx
     173:	8b 45 0c             	mov    0xc(%ebp),%eax
     176:	01 d0                	add    %edx,%eax
     178:	8b 00                	mov    (%eax),%eax
     17a:	c7 44 24 04 00 00 00 	movl   $0x0,0x4(%esp)
     181:	00 
     182:	89 04 24             	mov    %eax,(%esp)
     185:	e8 82 04 00 00       	call   60c <open>
     18a:	89 44 24 14          	mov    %eax,0x14(%esp)
     18e:	83 7c 24 14 00       	cmpl   $0x0,0x14(%esp)
     193:	79 2f                	jns    1c4 <main+0xba>
      printf(1, "grep: cannot open %s\n", argv[i]);
     195:	8b 44 24 1c          	mov    0x1c(%esp),%eax
     199:	8d 14 85 00 00 00 00 	lea    0x0(,%eax,4),%edx
     1a0:	8b 45 0c             	mov    0xc(%ebp),%eax
     1a3:	01 d0                	add    %edx,%eax
     1a5:	8b 00                	mov    (%eax),%eax
     1a7:	89 44 24 08          	mov    %eax,0x8(%esp)
     1ab:	c7 44 24 04 dc 11 00 	movl   $0x11dc,0x4(%esp)
     1b2:	00 
     1b3:	c7 04 24 01 00 00 00 	movl   $0x1,(%esp)
     1ba:	e8 aa 05 00 00       	call   769 <printf>
      exit();
     1bf:	e8 08 04 00 00       	call   5cc <exit>
    }
    grep(pattern, fd);
     1c4:	8b 44 24 14          	mov    0x14(%esp),%eax
     1c8:	89 44 24 04          	mov    %eax,0x4(%esp)
     1cc:	8b 44 24 18          	mov    0x18(%esp),%eax
     1d0:	89 04 24             	mov    %eax,(%esp)
     1d3:	e8 28 fe ff ff       	call   0 <grep>
    close(fd);
     1d8:	8b 44 24 14          	mov    0x14(%esp),%eax
     1dc:	89 04 24             	mov    %eax,(%esp)
     1df:	e8 10 04 00 00       	call   5f4 <close>
  if(argc <= 2){
    grep(pattern, 0);
    exit();
  }

  for(i = 2; i < argc; i++){
     1e4:	83 44 24 1c 01       	addl   $0x1,0x1c(%esp)
     1e9:	8b 44 24 1c          	mov    0x1c(%esp),%eax
     1ed:	3b 45 08             	cmp    0x8(%ebp),%eax
     1f0:	0f 8c 72 ff ff ff    	jl     168 <main+0x5e>
      exit();
    }
    grep(pattern, fd);
    close(fd);
  }
  exit();
     1f6:	e8 d1 03 00 00       	call   5cc <exit>

000001fb <match>:
int matchhere(char*, char*);
int matchstar(int, char*, char*);

int
match(char *re, char *text)
{
     1fb:	55                   	push   %ebp
     1fc:	89 e5                	mov    %esp,%ebp
     1fe:	83 ec 18             	sub    $0x18,%esp
  if(re[0] == '^')
     201:	8b 45 08             	mov    0x8(%ebp),%eax
     204:	0f b6 00             	movzbl (%eax),%eax
     207:	3c 5e                	cmp    $0x5e,%al
     209:	75 17                	jne    222 <match+0x27>
    return matchhere(re+1, text);
     20b:	8b 45 08             	mov    0x8(%ebp),%eax
     20e:	8d 50 01             	lea    0x1(%eax),%edx
     211:	8b 45 0c             	mov    0xc(%ebp),%eax
     214:	89 44 24 04          	mov    %eax,0x4(%esp)
     218:	89 14 24             	mov    %edx,(%esp)
     21b:	e8 39 00 00 00       	call   259 <matchhere>
     220:	eb 35                	jmp    257 <match+0x5c>
  do{  // must look at empty string
    if(matchhere(re, text))
     222:	8b 45 0c             	mov    0xc(%ebp),%eax
     225:	89 44 24 04          	mov    %eax,0x4(%esp)
     229:	8b 45 08             	mov    0x8(%ebp),%eax
     22c:	89 04 24             	mov    %eax,(%esp)
     22f:	e8 25 00 00 00       	call   259 <matchhere>
     234:	85 c0                	test   %eax,%eax
     236:	74 07                	je     23f <match+0x44>
      return 1;
     238:	b8 01 00 00 00       	mov    $0x1,%eax
     23d:	eb 18                	jmp    257 <match+0x5c>
  }while(*text++ != '\0');
     23f:	8b 45 0c             	mov    0xc(%ebp),%eax
     242:	0f b6 00             	movzbl (%eax),%eax
     245:	84 c0                	test   %al,%al
     247:	0f 95 c0             	setne  %al
     24a:	83 45 0c 01          	addl   $0x1,0xc(%ebp)
     24e:	84 c0                	test   %al,%al
     250:	75 d0                	jne    222 <match+0x27>
  return 0;
     252:	b8 00 00 00 00       	mov    $0x0,%eax
}
     257:	c9                   	leave  
     258:	c3                   	ret    

00000259 <matchhere>:

// matchhere: search for re at beginning of text
int matchhere(char *re, char *text)
{
     259:	55                   	push   %ebp
     25a:	89 e5                	mov    %esp,%ebp
     25c:	83 ec 18             	sub    $0x18,%esp
  if(re[0] == '\0')
     25f:	8b 45 08             	mov    0x8(%ebp),%eax
     262:	0f b6 00             	movzbl (%eax),%eax
     265:	84 c0                	test   %al,%al
     267:	75 0a                	jne    273 <matchhere+0x1a>
    return 1;
     269:	b8 01 00 00 00       	mov    $0x1,%eax
     26e:	e9 9b 00 00 00       	jmp    30e <matchhere+0xb5>
  if(re[1] == '*')
     273:	8b 45 08             	mov    0x8(%ebp),%eax
     276:	83 c0 01             	add    $0x1,%eax
     279:	0f b6 00             	movzbl (%eax),%eax
     27c:	3c 2a                	cmp    $0x2a,%al
     27e:	75 24                	jne    2a4 <matchhere+0x4b>
    return matchstar(re[0], re+2, text);
     280:	8b 45 08             	mov    0x8(%ebp),%eax
     283:	8d 48 02             	lea    0x2(%eax),%ecx
     286:	8b 45 08             	mov    0x8(%ebp),%eax
     289:	0f b6 00             	movzbl (%eax),%eax
     28c:	0f be c0             	movsbl %al,%eax
     28f:	8b 55 0c             	mov    0xc(%ebp),%edx
     292:	89 54 24 08          	mov    %edx,0x8(%esp)
     296:	89 4c 24 04          	mov    %ecx,0x4(%esp)
     29a:	89 04 24             	mov    %eax,(%esp)
     29d:	e8 6e 00 00 00       	call   310 <matchstar>
     2a2:	eb 6a                	jmp    30e <matchhere+0xb5>
  if(re[0] == '$' && re[1] == '\0')
     2a4:	8b 45 08             	mov    0x8(%ebp),%eax
     2a7:	0f b6 00             	movzbl (%eax),%eax
     2aa:	3c 24                	cmp    $0x24,%al
     2ac:	75 1d                	jne    2cb <matchhere+0x72>
     2ae:	8b 45 08             	mov    0x8(%ebp),%eax
     2b1:	83 c0 01             	add    $0x1,%eax
     2b4:	0f b6 00             	movzbl (%eax),%eax
     2b7:	84 c0                	test   %al,%al
     2b9:	75 10                	jne    2cb <matchhere+0x72>
    return *text == '\0';
     2bb:	8b 45 0c             	mov    0xc(%ebp),%eax
     2be:	0f b6 00             	movzbl (%eax),%eax
     2c1:	84 c0                	test   %al,%al
     2c3:	0f 94 c0             	sete   %al
     2c6:	0f b6 c0             	movzbl %al,%eax
     2c9:	eb 43                	jmp    30e <matchhere+0xb5>
  if(*text!='\0' && (re[0]=='.' || re[0]==*text))
     2cb:	8b 45 0c             	mov    0xc(%ebp),%eax
     2ce:	0f b6 00             	movzbl (%eax),%eax
     2d1:	84 c0                	test   %al,%al
     2d3:	74 34                	je     309 <matchhere+0xb0>
     2d5:	8b 45 08             	mov    0x8(%ebp),%eax
     2d8:	0f b6 00             	movzbl (%eax),%eax
     2db:	3c 2e                	cmp    $0x2e,%al
     2dd:	74 10                	je     2ef <matchhere+0x96>
     2df:	8b 45 08             	mov    0x8(%ebp),%eax
     2e2:	0f b6 10             	movzbl (%eax),%edx
     2e5:	8b 45 0c             	mov    0xc(%ebp),%eax
     2e8:	0f b6 00             	movzbl (%eax),%eax
     2eb:	38 c2                	cmp    %al,%dl
     2ed:	75 1a                	jne    309 <matchhere+0xb0>
    return matchhere(re+1, text+1);
     2ef:	8b 45 0c             	mov    0xc(%ebp),%eax
     2f2:	8d 50 01             	lea    0x1(%eax),%edx
     2f5:	8b 45 08             	mov    0x8(%ebp),%eax
     2f8:	83 c0 01             	add    $0x1,%eax
     2fb:	89 54 24 04          	mov    %edx,0x4(%esp)
     2ff:	89 04 24             	mov    %eax,(%esp)
     302:	e8 52 ff ff ff       	call   259 <matchhere>
     307:	eb 05                	jmp    30e <matchhere+0xb5>
  return 0;
     309:	b8 00 00 00 00       	mov    $0x0,%eax
}
     30e:	c9                   	leave  
     30f:	c3                   	ret    

00000310 <matchstar>:

// matchstar: search for c*re at beginning of text
int matchstar(int c, char *re, char *text)
{
     310:	55                   	push   %ebp
     311:	89 e5                	mov    %esp,%ebp
     313:	83 ec 18             	sub    $0x18,%esp
  do{  // a * matches zero or more instances
    if(matchhere(re, text))
     316:	8b 45 10             	mov    0x10(%ebp),%eax
     319:	89 44 24 04          	mov    %eax,0x4(%esp)
     31d:	8b 45 0c             	mov    0xc(%ebp),%eax
     320:	89 04 24             	mov    %eax,(%esp)
     323:	e8 31 ff ff ff       	call   259 <matchhere>
     328:	85 c0                	test   %eax,%eax
     32a:	74 07                	je     333 <matchstar+0x23>
      return 1;
     32c:	b8 01 00 00 00       	mov    $0x1,%eax
     331:	eb 2c                	jmp    35f <matchstar+0x4f>
  }while(*text!='\0' && (*text++==c || c=='.'));
     333:	8b 45 10             	mov    0x10(%ebp),%eax
     336:	0f b6 00             	movzbl (%eax),%eax
     339:	84 c0                	test   %al,%al
     33b:	74 1d                	je     35a <matchstar+0x4a>
     33d:	8b 45 10             	mov    0x10(%ebp),%eax
     340:	0f b6 00             	movzbl (%eax),%eax
     343:	0f be c0             	movsbl %al,%eax
     346:	3b 45 08             	cmp    0x8(%ebp),%eax
     349:	0f 94 c0             	sete   %al
     34c:	83 45 10 01          	addl   $0x1,0x10(%ebp)
     350:	84 c0                	test   %al,%al
     352:	75 c2                	jne    316 <matchstar+0x6>
     354:	83 7d 08 2e          	cmpl   $0x2e,0x8(%ebp)
     358:	74 bc                	je     316 <matchstar+0x6>
  return 0;
     35a:	b8 00 00 00 00       	mov    $0x0,%eax
}
     35f:	c9                   	leave  
     360:	c3                   	ret    
     361:	66 90                	xchg   %ax,%ax
     363:	90                   	nop

00000364 <stosb>:
               "cc");
}

static inline void
stosb(void *addr, int data, int cnt)
{
     364:	55                   	push   %ebp
     365:	89 e5                	mov    %esp,%ebp
     367:	57                   	push   %edi
     368:	53                   	push   %ebx
  asm volatile("cld; rep stosb" :
     369:	8b 4d 08             	mov    0x8(%ebp),%ecx
     36c:	8b 55 10             	mov    0x10(%ebp),%edx
     36f:	8b 45 0c             	mov    0xc(%ebp),%eax
     372:	89 cb                	mov    %ecx,%ebx
     374:	89 df                	mov    %ebx,%edi
     376:	89 d1                	mov    %edx,%ecx
     378:	fc                   	cld    
     379:	f3 aa                	rep stos %al,%es:(%edi)
     37b:	89 ca                	mov    %ecx,%edx
     37d:	89 fb                	mov    %edi,%ebx
     37f:	89 5d 08             	mov    %ebx,0x8(%ebp)
     382:	89 55 10             	mov    %edx,0x10(%ebp)
               "=D" (addr), "=c" (cnt) :
               "0" (addr), "1" (cnt), "a" (data) :
               "memory", "cc");
}
     385:	5b                   	pop    %ebx
     386:	5f                   	pop    %edi
     387:	5d                   	pop    %ebp
     388:	c3                   	ret    

00000389 <strcpy>:
#include "user.h"
#include "x86.h"

char*
strcpy(char *s, char *t)
{
     389:	55                   	push   %ebp
     38a:	89 e5                	mov    %esp,%ebp
     38c:	83 ec 10             	sub    $0x10,%esp
  char *os;

  os = s;
     38f:	8b 45 08             	mov    0x8(%ebp),%eax
     392:	89 45 fc             	mov    %eax,-0x4(%ebp)
  while((*s++ = *t++) != 0)
     395:	90                   	nop
     396:	8b 45 0c             	mov    0xc(%ebp),%eax
     399:	0f b6 10             	movzbl (%eax),%edx
     39c:	8b 45 08             	mov    0x8(%ebp),%eax
     39f:	88 10                	mov    %dl,(%eax)
     3a1:	8b 45 08             	mov    0x8(%ebp),%eax
     3a4:	0f b6 00             	movzbl (%eax),%eax
     3a7:	84 c0                	test   %al,%al
     3a9:	0f 95 c0             	setne  %al
     3ac:	83 45 08 01          	addl   $0x1,0x8(%ebp)
     3b0:	83 45 0c 01          	addl   $0x1,0xc(%ebp)
     3b4:	84 c0                	test   %al,%al
     3b6:	75 de                	jne    396 <strcpy+0xd>
    ;
  return os;
     3b8:	8b 45 fc             	mov    -0x4(%ebp),%eax
}
     3bb:	c9                   	leave  
     3bc:	c3                   	ret    

000003bd <strcmp>:

int
strcmp(const char *p, const char *q)
{
     3bd:	55                   	push   %ebp
     3be:	89 e5                	mov    %esp,%ebp
  while(*p && *p == *q)
     3c0:	eb 08                	jmp    3ca <strcmp+0xd>
    p++, q++;
     3c2:	83 45 08 01          	addl   $0x1,0x8(%ebp)
     3c6:	83 45 0c 01          	addl   $0x1,0xc(%ebp)
}

int
strcmp(const char *p, const char *q)
{
  while(*p && *p == *q)
     3ca:	8b 45 08             	mov    0x8(%ebp),%eax
     3cd:	0f b6 00             	movzbl (%eax),%eax
     3d0:	84 c0                	test   %al,%al
     3d2:	74 10                	je     3e4 <strcmp+0x27>
     3d4:	8b 45 08             	mov    0x8(%ebp),%eax
     3d7:	0f b6 10             	movzbl (%eax),%edx
     3da:	8b 45 0c             	mov    0xc(%ebp),%eax
     3dd:	0f b6 00             	movzbl (%eax),%eax
     3e0:	38 c2                	cmp    %al,%dl
     3e2:	74 de                	je     3c2 <strcmp+0x5>
    p++, q++;
  return (uchar)*p - (uchar)*q;
     3e4:	8b 45 08             	mov    0x8(%ebp),%eax
     3e7:	0f b6 00             	movzbl (%eax),%eax
     3ea:	0f b6 d0             	movzbl %al,%edx
     3ed:	8b 45 0c             	mov    0xc(%ebp),%eax
     3f0:	0f b6 00             	movzbl (%eax),%eax
     3f3:	0f b6 c0             	movzbl %al,%eax
     3f6:	89 d1                	mov    %edx,%ecx
     3f8:	29 c1                	sub    %eax,%ecx
     3fa:	89 c8                	mov    %ecx,%eax
}
     3fc:	5d                   	pop    %ebp
     3fd:	c3                   	ret    

000003fe <strlen>:

uint
strlen(char *s)
{
     3fe:	55                   	push   %ebp
     3ff:	89 e5                	mov    %esp,%ebp
     401:	83 ec 10             	sub    $0x10,%esp
  int n;

  for(n = 0; s[n]; n++)
     404:	c7 45 fc 00 00 00 00 	movl   $0x0,-0x4(%ebp)
     40b:	eb 04                	jmp    411 <strlen+0x13>
     40d:	83 45 fc 01          	addl   $0x1,-0x4(%ebp)
     411:	8b 55 fc             	mov    -0x4(%ebp),%edx
     414:	8b 45 08             	mov    0x8(%ebp),%eax
     417:	01 d0                	add    %edx,%eax
     419:	0f b6 00             	movzbl (%eax),%eax
     41c:	84 c0                	test   %al,%al
     41e:	75 ed                	jne    40d <strlen+0xf>
    ;
  return n;
     420:	8b 45 fc             	mov    -0x4(%ebp),%eax
}
     423:	c9                   	leave  
     424:	c3                   	ret    

00000425 <memset>:

void*
memset(void *dst, int c, uint n)
{
     425:	55                   	push   %ebp
     426:	89 e5                	mov    %esp,%ebp
     428:	83 ec 0c             	sub    $0xc,%esp
  stosb(dst, c, n);
     42b:	8b 45 10             	mov    0x10(%ebp),%eax
     42e:	89 44 24 08          	mov    %eax,0x8(%esp)
     432:	8b 45 0c             	mov    0xc(%ebp),%eax
     435:	89 44 24 04          	mov    %eax,0x4(%esp)
     439:	8b 45 08             	mov    0x8(%ebp),%eax
     43c:	89 04 24             	mov    %eax,(%esp)
     43f:	e8 20 ff ff ff       	call   364 <stosb>
  return dst;
     444:	8b 45 08             	mov    0x8(%ebp),%eax
}
     447:	c9                   	leave  
     448:	c3                   	ret    

00000449 <strchr>:

char*
strchr(const char *s, char c)
{
     449:	55                   	push   %ebp
     44a:	89 e5                	mov    %esp,%ebp
     44c:	83 ec 04             	sub    $0x4,%esp
     44f:	8b 45 0c             	mov    0xc(%ebp),%eax
     452:	88 45 fc             	mov    %al,-0x4(%ebp)
  for(; *s; s++)
     455:	eb 14                	jmp    46b <strchr+0x22>
    if(*s == c)
     457:	8b 45 08             	mov    0x8(%ebp),%eax
     45a:	0f b6 00             	movzbl (%eax),%eax
     45d:	3a 45 fc             	cmp    -0x4(%ebp),%al
     460:	75 05                	jne    467 <strchr+0x1e>
      return (char*)s;
     462:	8b 45 08             	mov    0x8(%ebp),%eax
     465:	eb 13                	jmp    47a <strchr+0x31>
}

char*
strchr(const char *s, char c)
{
  for(; *s; s++)
     467:	83 45 08 01          	addl   $0x1,0x8(%ebp)
     46b:	8b 45 08             	mov    0x8(%ebp),%eax
     46e:	0f b6 00             	movzbl (%eax),%eax
     471:	84 c0                	test   %al,%al
     473:	75 e2                	jne    457 <strchr+0xe>
    if(*s == c)
      return (char*)s;
  return 0;
     475:	b8 00 00 00 00       	mov    $0x0,%eax
}
     47a:	c9                   	leave  
     47b:	c3                   	ret    

0000047c <gets>:

char*
gets(char *buf, int max)
{
     47c:	55                   	push   %ebp
     47d:	89 e5                	mov    %esp,%ebp
     47f:	83 ec 28             	sub    $0x28,%esp
  int i, cc;
  char c;

  for(i=0; i+1 < max; ){
     482:	c7 45 f4 00 00 00 00 	movl   $0x0,-0xc(%ebp)
     489:	eb 46                	jmp    4d1 <gets+0x55>
    cc = read(0, &c, 1);
     48b:	c7 44 24 08 01 00 00 	movl   $0x1,0x8(%esp)
     492:	00 
     493:	8d 45 ef             	lea    -0x11(%ebp),%eax
     496:	89 44 24 04          	mov    %eax,0x4(%esp)
     49a:	c7 04 24 00 00 00 00 	movl   $0x0,(%esp)
     4a1:	e8 3e 01 00 00       	call   5e4 <read>
     4a6:	89 45 f0             	mov    %eax,-0x10(%ebp)
    if(cc < 1)
     4a9:	83 7d f0 00          	cmpl   $0x0,-0x10(%ebp)
     4ad:	7e 2f                	jle    4de <gets+0x62>
      break;
    buf[i++] = c;
     4af:	8b 55 f4             	mov    -0xc(%ebp),%edx
     4b2:	8b 45 08             	mov    0x8(%ebp),%eax
     4b5:	01 c2                	add    %eax,%edx
     4b7:	0f b6 45 ef          	movzbl -0x11(%ebp),%eax
     4bb:	88 02                	mov    %al,(%edx)
     4bd:	83 45 f4 01          	addl   $0x1,-0xc(%ebp)
    if(c == '\n' || c == '\r')
     4c1:	0f b6 45 ef          	movzbl -0x11(%ebp),%eax
     4c5:	3c 0a                	cmp    $0xa,%al
     4c7:	74 16                	je     4df <gets+0x63>
     4c9:	0f b6 45 ef          	movzbl -0x11(%ebp),%eax
     4cd:	3c 0d                	cmp    $0xd,%al
     4cf:	74 0e                	je     4df <gets+0x63>
gets(char *buf, int max)
{
  int i, cc;
  char c;

  for(i=0; i+1 < max; ){
     4d1:	8b 45 f4             	mov    -0xc(%ebp),%eax
     4d4:	83 c0 01             	add    $0x1,%eax
     4d7:	3b 45 0c             	cmp    0xc(%ebp),%eax
     4da:	7c af                	jl     48b <gets+0xf>
     4dc:	eb 01                	jmp    4df <gets+0x63>
    cc = read(0, &c, 1);
    if(cc < 1)
      break;
     4de:	90                   	nop
    buf[i++] = c;
    if(c == '\n' || c == '\r')
      break;
  }
  buf[i] = '\0';
     4df:	8b 55 f4             	mov    -0xc(%ebp),%edx
     4e2:	8b 45 08             	mov    0x8(%ebp),%eax
     4e5:	01 d0                	add    %edx,%eax
     4e7:	c6 00 00             	movb   $0x0,(%eax)
  return buf;
     4ea:	8b 45 08             	mov    0x8(%ebp),%eax
}
     4ed:	c9                   	leave  
     4ee:	c3                   	ret    

000004ef <stat>:

int
stat(char *n, struct stat *st)
{
     4ef:	55                   	push   %ebp
     4f0:	89 e5                	mov    %esp,%ebp
     4f2:	83 ec 28             	sub    $0x28,%esp
  int fd;
  int r;

  fd = open(n, O_RDONLY);
     4f5:	c7 44 24 04 00 00 00 	movl   $0x0,0x4(%esp)
     4fc:	00 
     4fd:	8b 45 08             	mov    0x8(%ebp),%eax
     500:	89 04 24             	mov    %eax,(%esp)
     503:	e8 04 01 00 00       	call   60c <open>
     508:	89 45 f4             	mov    %eax,-0xc(%ebp)
  if(fd < 0)
     50b:	83 7d f4 00          	cmpl   $0x0,-0xc(%ebp)
     50f:	79 07                	jns    518 <stat+0x29>
    return -1;
     511:	b8 ff ff ff ff       	mov    $0xffffffff,%eax
     516:	eb 23                	jmp    53b <stat+0x4c>
  r = fstat(fd, st);
     518:	8b 45 0c             	mov    0xc(%ebp),%eax
     51b:	89 44 24 04          	mov    %eax,0x4(%esp)
     51f:	8b 45 f4             	mov    -0xc(%ebp),%eax
     522:	89 04 24             	mov    %eax,(%esp)
     525:	e8 fa 00 00 00       	call   624 <fstat>
     52a:	89 45 f0             	mov    %eax,-0x10(%ebp)
  close(fd);
     52d:	8b 45 f4             	mov    -0xc(%ebp),%eax
     530:	89 04 24             	mov    %eax,(%esp)
     533:	e8 bc 00 00 00       	call   5f4 <close>
  return r;
     538:	8b 45 f0             	mov    -0x10(%ebp),%eax
}
     53b:	c9                   	leave  
     53c:	c3                   	ret    

0000053d <atoi>:

int
atoi(const char *s)
{
     53d:	55                   	push   %ebp
     53e:	89 e5                	mov    %esp,%ebp
     540:	83 ec 10             	sub    $0x10,%esp
  int n;

  n = 0;
     543:	c7 45 fc 00 00 00 00 	movl   $0x0,-0x4(%ebp)
  while('0' <= *s && *s <= '9')
     54a:	eb 23                	jmp    56f <atoi+0x32>
    n = n*10 + *s++ - '0';
     54c:	8b 55 fc             	mov    -0x4(%ebp),%edx
     54f:	89 d0                	mov    %edx,%eax
     551:	c1 e0 02             	shl    $0x2,%eax
     554:	01 d0                	add    %edx,%eax
     556:	01 c0                	add    %eax,%eax
     558:	89 c2                	mov    %eax,%edx
     55a:	8b 45 08             	mov    0x8(%ebp),%eax
     55d:	0f b6 00             	movzbl (%eax),%eax
     560:	0f be c0             	movsbl %al,%eax
     563:	01 d0                	add    %edx,%eax
     565:	83 e8 30             	sub    $0x30,%eax
     568:	89 45 fc             	mov    %eax,-0x4(%ebp)
     56b:	83 45 08 01          	addl   $0x1,0x8(%ebp)
atoi(const char *s)
{
  int n;

  n = 0;
  while('0' <= *s && *s <= '9')
     56f:	8b 45 08             	mov    0x8(%ebp),%eax
     572:	0f b6 00             	movzbl (%eax),%eax
     575:	3c 2f                	cmp    $0x2f,%al
     577:	7e 0a                	jle    583 <atoi+0x46>
     579:	8b 45 08             	mov    0x8(%ebp),%eax
     57c:	0f b6 00             	movzbl (%eax),%eax
     57f:	3c 39                	cmp    $0x39,%al
     581:	7e c9                	jle    54c <atoi+0xf>
    n = n*10 + *s++ - '0';
  return n;
     583:	8b 45 fc             	mov    -0x4(%ebp),%eax
}
     586:	c9                   	leave  
     587:	c3                   	ret    

00000588 <memmove>:

void*
memmove(void *vdst, void *vsrc, int n)
{
     588:	55                   	push   %ebp
     589:	89 e5                	mov    %esp,%ebp
     58b:	83 ec 10             	sub    $0x10,%esp
  char *dst, *src;
  
  dst = vdst;
     58e:	8b 45 08             	mov    0x8(%ebp),%eax
     591:	89 45 fc             	mov    %eax,-0x4(%ebp)
  src = vsrc;
     594:	8b 45 0c             	mov    0xc(%ebp),%eax
     597:	89 45 f8             	mov    %eax,-0x8(%ebp)
  while(n-- > 0)
     59a:	eb 13                	jmp    5af <memmove+0x27>
    *dst++ = *src++;
     59c:	8b 45 f8             	mov    -0x8(%ebp),%eax
     59f:	0f b6 10             	movzbl (%eax),%edx
     5a2:	8b 45 fc             	mov    -0x4(%ebp),%eax
     5a5:	88 10                	mov    %dl,(%eax)
     5a7:	83 45 fc 01          	addl   $0x1,-0x4(%ebp)
     5ab:	83 45 f8 01          	addl   $0x1,-0x8(%ebp)
{
  char *dst, *src;
  
  dst = vdst;
  src = vsrc;
  while(n-- > 0)
     5af:	83 7d 10 00          	cmpl   $0x0,0x10(%ebp)
     5b3:	0f 9f c0             	setg   %al
     5b6:	83 6d 10 01          	subl   $0x1,0x10(%ebp)
     5ba:	84 c0                	test   %al,%al
     5bc:	75 de                	jne    59c <memmove+0x14>
    *dst++ = *src++;
  return vdst;
     5be:	8b 45 08             	mov    0x8(%ebp),%eax
}
     5c1:	c9                   	leave  
     5c2:	c3                   	ret    
     5c3:	90                   	nop

000005c4 <fork>:
  name: \
    movl $SYS_ ## name, %eax; \
    int $T_SYSCALL; \
    ret

SYSCALL(fork)
     5c4:	b8 01 00 00 00       	mov    $0x1,%eax
     5c9:	cd 40                	int    $0x40
     5cb:	c3                   	ret    

000005cc <exit>:
SYSCALL(exit)
     5cc:	b8 02 00 00 00       	mov    $0x2,%eax
     5d1:	cd 40                	int    $0x40
     5d3:	c3                   	ret    

000005d4 <wait>:
SYSCALL(wait)
     5d4:	b8 03 00 00 00       	mov    $0x3,%eax
     5d9:	cd 40                	int    $0x40
     5db:	c3                   	ret    

000005dc <pipe>:
SYSCALL(pipe)
     5dc:	b8 04 00 00 00       	mov    $0x4,%eax
     5e1:	cd 40                	int    $0x40
     5e3:	c3                   	ret    

000005e4 <read>:
SYSCALL(read)
     5e4:	b8 05 00 00 00       	mov    $0x5,%eax
     5e9:	cd 40                	int    $0x40
     5eb:	c3                   	ret    

000005ec <write>:
SYSCALL(write)
     5ec:	b8 10 00 00 00       	mov    $0x10,%eax
     5f1:	cd 40                	int    $0x40
     5f3:	c3                   	ret    

000005f4 <close>:
SYSCALL(close)
     5f4:	b8 15 00 00 00       	mov    $0x15,%eax
     5f9:	cd 40                	int    $0x40
     5fb:	c3                   	ret    

000005fc <kill>:
SYSCALL(kill)
     5fc:	b8 06 00 00 00       	mov    $0x6,%eax
     601:	cd 40                	int    $0x40
     603:	c3                   	ret    

00000604 <exec>:
SYSCALL(exec)
     604:	b8 07 00 00 00       	mov    $0x7,%eax
     609:	cd 40                	int    $0x40
     60b:	c3                   	ret    

0000060c <open>:
SYSCALL(open)
     60c:	b8 0f 00 00 00       	mov    $0xf,%eax
     611:	cd 40                	int    $0x40
     613:	c3                   	ret    

00000614 <mknod>:
SYSCALL(mknod)
     614:	b8 11 00 00 00       	mov    $0x11,%eax
     619:	cd 40                	int    $0x40
     61b:	c3                   	ret    

0000061c <unlink>:
SYSCALL(unlink)
     61c:	b8 12 00 00 00       	mov    $0x12,%eax
     621:	cd 40                	int    $0x40
     623:	c3                   	ret    

00000624 <fstat>:
SYSCALL(fstat)
     624:	b8 08 00 00 00       	mov    $0x8,%eax
     629:	cd 40                	int    $0x40
     62b:	c3                   	ret    

0000062c <link>:
SYSCALL(link)
     62c:	b8 13 00 00 00       	mov    $0x13,%eax
     631:	cd 40                	int    $0x40
     633:	c3                   	ret    

00000634 <mkdir>:
SYSCALL(mkdir)
     634:	b8 14 00 00 00       	mov    $0x14,%eax
     639:	cd 40                	int    $0x40
     63b:	c3                   	ret    

0000063c <chdir>:
SYSCALL(chdir)
     63c:	b8 09 00 00 00       	mov    $0x9,%eax
     641:	cd 40                	int    $0x40
     643:	c3                   	ret    

00000644 <dup>:
SYSCALL(dup)
     644:	b8 0a 00 00 00       	mov    $0xa,%eax
     649:	cd 40                	int    $0x40
     64b:	c3                   	ret    

0000064c <getpid>:
SYSCALL(getpid)
     64c:	b8 0b 00 00 00       	mov    $0xb,%eax
     651:	cd 40                	int    $0x40
     653:	c3                   	ret    

00000654 <sbrk>:
SYSCALL(sbrk)
     654:	b8 0c 00 00 00       	mov    $0xc,%eax
     659:	cd 40                	int    $0x40
     65b:	c3                   	ret    

0000065c <sleep>:
SYSCALL(sleep)
     65c:	b8 0d 00 00 00       	mov    $0xd,%eax
     661:	cd 40                	int    $0x40
     663:	c3                   	ret    

00000664 <uptime>:
SYSCALL(uptime)
     664:	b8 0e 00 00 00       	mov    $0xe,%eax
     669:	cd 40                	int    $0x40
     66b:	c3                   	ret    

0000066c <signal>:

//our addition
SYSCALL(signal)
     66c:	b8 1f 00 00 00       	mov    $0x1f,%eax
     671:	cd 40                	int    $0x40
     673:	c3                   	ret    

00000674 <sigsend>:
SYSCALL(sigsend)
     674:	b8 20 00 00 00       	mov    $0x20,%eax
     679:	cd 40                	int    $0x40
     67b:	c3                   	ret    

0000067c <alarm>:
SYSCALL(alarm)
     67c:	b8 21 00 00 00       	mov    $0x21,%eax
     681:	cd 40                	int    $0x40
     683:	c3                   	ret    

00000684 <getTicks>:
SYSCALL(getTicks)
     684:	b8 22 00 00 00       	mov    $0x22,%eax
     689:	cd 40                	int    $0x40
     68b:	c3                   	ret    

0000068c <putc>:
#include "stat.h"
#include "user.h"

static void
putc(int fd, char c)
{
     68c:	55                   	push   %ebp
     68d:	89 e5                	mov    %esp,%ebp
     68f:	83 ec 28             	sub    $0x28,%esp
     692:	8b 45 0c             	mov    0xc(%ebp),%eax
     695:	88 45 f4             	mov    %al,-0xc(%ebp)
  write(fd, &c, 1);
     698:	c7 44 24 08 01 00 00 	movl   $0x1,0x8(%esp)
     69f:	00 
     6a0:	8d 45 f4             	lea    -0xc(%ebp),%eax
     6a3:	89 44 24 04          	mov    %eax,0x4(%esp)
     6a7:	8b 45 08             	mov    0x8(%ebp),%eax
     6aa:	89 04 24             	mov    %eax,(%esp)
     6ad:	e8 3a ff ff ff       	call   5ec <write>
}
     6b2:	c9                   	leave  
     6b3:	c3                   	ret    

000006b4 <printint>:

static void
printint(int fd, int xx, int base, int sgn)
{
     6b4:	55                   	push   %ebp
     6b5:	89 e5                	mov    %esp,%ebp
     6b7:	83 ec 48             	sub    $0x48,%esp
  static char digits[] = "0123456789ABCDEF";
  char buf[16];
  int i, neg;
  uint x;

  neg = 0;
     6ba:	c7 45 f0 00 00 00 00 	movl   $0x0,-0x10(%ebp)
  if(sgn && xx < 0){
     6c1:	83 7d 14 00          	cmpl   $0x0,0x14(%ebp)
     6c5:	74 17                	je     6de <printint+0x2a>
     6c7:	83 7d 0c 00          	cmpl   $0x0,0xc(%ebp)
     6cb:	79 11                	jns    6de <printint+0x2a>
    neg = 1;
     6cd:	c7 45 f0 01 00 00 00 	movl   $0x1,-0x10(%ebp)
    x = -xx;
     6d4:	8b 45 0c             	mov    0xc(%ebp),%eax
     6d7:	f7 d8                	neg    %eax
     6d9:	89 45 ec             	mov    %eax,-0x14(%ebp)
     6dc:	eb 06                	jmp    6e4 <printint+0x30>
  } else {
    x = xx;
     6de:	8b 45 0c             	mov    0xc(%ebp),%eax
     6e1:	89 45 ec             	mov    %eax,-0x14(%ebp)
  }

  i = 0;
     6e4:	c7 45 f4 00 00 00 00 	movl   $0x0,-0xc(%ebp)
  do{
    buf[i++] = digits[x % base];
     6eb:	8b 4d 10             	mov    0x10(%ebp),%ecx
     6ee:	8b 45 ec             	mov    -0x14(%ebp),%eax
     6f1:	ba 00 00 00 00       	mov    $0x0,%edx
     6f6:	f7 f1                	div    %ecx
     6f8:	89 d0                	mov    %edx,%eax
     6fa:	0f b6 80 d0 16 00 00 	movzbl 0x16d0(%eax),%eax
     701:	8d 4d dc             	lea    -0x24(%ebp),%ecx
     704:	8b 55 f4             	mov    -0xc(%ebp),%edx
     707:	01 ca                	add    %ecx,%edx
     709:	88 02                	mov    %al,(%edx)
     70b:	83 45 f4 01          	addl   $0x1,-0xc(%ebp)
  }while((x /= base) != 0);
     70f:	8b 55 10             	mov    0x10(%ebp),%edx
     712:	89 55 d4             	mov    %edx,-0x2c(%ebp)
     715:	8b 45 ec             	mov    -0x14(%ebp),%eax
     718:	ba 00 00 00 00       	mov    $0x0,%edx
     71d:	f7 75 d4             	divl   -0x2c(%ebp)
     720:	89 45 ec             	mov    %eax,-0x14(%ebp)
     723:	83 7d ec 00          	cmpl   $0x0,-0x14(%ebp)
     727:	75 c2                	jne    6eb <printint+0x37>
  if(neg)
     729:	83 7d f0 00          	cmpl   $0x0,-0x10(%ebp)
     72d:	74 2e                	je     75d <printint+0xa9>
    buf[i++] = '-';
     72f:	8d 55 dc             	lea    -0x24(%ebp),%edx
     732:	8b 45 f4             	mov    -0xc(%ebp),%eax
     735:	01 d0                	add    %edx,%eax
     737:	c6 00 2d             	movb   $0x2d,(%eax)
     73a:	83 45 f4 01          	addl   $0x1,-0xc(%ebp)

  while(--i >= 0)
     73e:	eb 1d                	jmp    75d <printint+0xa9>
    putc(fd, buf[i]);
     740:	8d 55 dc             	lea    -0x24(%ebp),%edx
     743:	8b 45 f4             	mov    -0xc(%ebp),%eax
     746:	01 d0                	add    %edx,%eax
     748:	0f b6 00             	movzbl (%eax),%eax
     74b:	0f be c0             	movsbl %al,%eax
     74e:	89 44 24 04          	mov    %eax,0x4(%esp)
     752:	8b 45 08             	mov    0x8(%ebp),%eax
     755:	89 04 24             	mov    %eax,(%esp)
     758:	e8 2f ff ff ff       	call   68c <putc>
    buf[i++] = digits[x % base];
  }while((x /= base) != 0);
  if(neg)
    buf[i++] = '-';

  while(--i >= 0)
     75d:	83 6d f4 01          	subl   $0x1,-0xc(%ebp)
     761:	83 7d f4 00          	cmpl   $0x0,-0xc(%ebp)
     765:	79 d9                	jns    740 <printint+0x8c>
    putc(fd, buf[i]);
}
     767:	c9                   	leave  
     768:	c3                   	ret    

00000769 <printf>:

// Print to the given fd. Only understands %d, %x, %p, %s.
void
printf(int fd, char *fmt, ...)
{
     769:	55                   	push   %ebp
     76a:	89 e5                	mov    %esp,%ebp
     76c:	83 ec 38             	sub    $0x38,%esp
  char *s;
  int c, i, state;
  uint *ap;

  state = 0;
     76f:	c7 45 ec 00 00 00 00 	movl   $0x0,-0x14(%ebp)
  ap = (uint*)(void*)&fmt + 1;
     776:	8d 45 0c             	lea    0xc(%ebp),%eax
     779:	83 c0 04             	add    $0x4,%eax
     77c:	89 45 e8             	mov    %eax,-0x18(%ebp)
  for(i = 0; fmt[i]; i++){
     77f:	c7 45 f0 00 00 00 00 	movl   $0x0,-0x10(%ebp)
     786:	e9 7d 01 00 00       	jmp    908 <printf+0x19f>
    c = fmt[i] & 0xff;
     78b:	8b 55 0c             	mov    0xc(%ebp),%edx
     78e:	8b 45 f0             	mov    -0x10(%ebp),%eax
     791:	01 d0                	add    %edx,%eax
     793:	0f b6 00             	movzbl (%eax),%eax
     796:	0f be c0             	movsbl %al,%eax
     799:	25 ff 00 00 00       	and    $0xff,%eax
     79e:	89 45 e4             	mov    %eax,-0x1c(%ebp)
    if(state == 0){
     7a1:	83 7d ec 00          	cmpl   $0x0,-0x14(%ebp)
     7a5:	75 2c                	jne    7d3 <printf+0x6a>
      if(c == '%'){
     7a7:	83 7d e4 25          	cmpl   $0x25,-0x1c(%ebp)
     7ab:	75 0c                	jne    7b9 <printf+0x50>
        state = '%';
     7ad:	c7 45 ec 25 00 00 00 	movl   $0x25,-0x14(%ebp)
     7b4:	e9 4b 01 00 00       	jmp    904 <printf+0x19b>
      } else {
        putc(fd, c);
     7b9:	8b 45 e4             	mov    -0x1c(%ebp),%eax
     7bc:	0f be c0             	movsbl %al,%eax
     7bf:	89 44 24 04          	mov    %eax,0x4(%esp)
     7c3:	8b 45 08             	mov    0x8(%ebp),%eax
     7c6:	89 04 24             	mov    %eax,(%esp)
     7c9:	e8 be fe ff ff       	call   68c <putc>
     7ce:	e9 31 01 00 00       	jmp    904 <printf+0x19b>
      }
    } else if(state == '%'){
     7d3:	83 7d ec 25          	cmpl   $0x25,-0x14(%ebp)
     7d7:	0f 85 27 01 00 00    	jne    904 <printf+0x19b>
      if(c == 'd'){
     7dd:	83 7d e4 64          	cmpl   $0x64,-0x1c(%ebp)
     7e1:	75 2d                	jne    810 <printf+0xa7>
        printint(fd, *ap, 10, 1);
     7e3:	8b 45 e8             	mov    -0x18(%ebp),%eax
     7e6:	8b 00                	mov    (%eax),%eax
     7e8:	c7 44 24 0c 01 00 00 	movl   $0x1,0xc(%esp)
     7ef:	00 
     7f0:	c7 44 24 08 0a 00 00 	movl   $0xa,0x8(%esp)
     7f7:	00 
     7f8:	89 44 24 04          	mov    %eax,0x4(%esp)
     7fc:	8b 45 08             	mov    0x8(%ebp),%eax
     7ff:	89 04 24             	mov    %eax,(%esp)
     802:	e8 ad fe ff ff       	call   6b4 <printint>
        ap++;
     807:	83 45 e8 04          	addl   $0x4,-0x18(%ebp)
     80b:	e9 ed 00 00 00       	jmp    8fd <printf+0x194>
      } else if(c == 'x' || c == 'p'){
     810:	83 7d e4 78          	cmpl   $0x78,-0x1c(%ebp)
     814:	74 06                	je     81c <printf+0xb3>
     816:	83 7d e4 70          	cmpl   $0x70,-0x1c(%ebp)
     81a:	75 2d                	jne    849 <printf+0xe0>
        printint(fd, *ap, 16, 0);
     81c:	8b 45 e8             	mov    -0x18(%ebp),%eax
     81f:	8b 00                	mov    (%eax),%eax
     821:	c7 44 24 0c 00 00 00 	movl   $0x0,0xc(%esp)
     828:	00 
     829:	c7 44 24 08 10 00 00 	movl   $0x10,0x8(%esp)
     830:	00 
     831:	89 44 24 04          	mov    %eax,0x4(%esp)
     835:	8b 45 08             	mov    0x8(%ebp),%eax
     838:	89 04 24             	mov    %eax,(%esp)
     83b:	e8 74 fe ff ff       	call   6b4 <printint>
        ap++;
     840:	83 45 e8 04          	addl   $0x4,-0x18(%ebp)
     844:	e9 b4 00 00 00       	jmp    8fd <printf+0x194>
      } else if(c == 's'){
     849:	83 7d e4 73          	cmpl   $0x73,-0x1c(%ebp)
     84d:	75 46                	jne    895 <printf+0x12c>
        s = (char*)*ap;
     84f:	8b 45 e8             	mov    -0x18(%ebp),%eax
     852:	8b 00                	mov    (%eax),%eax
     854:	89 45 f4             	mov    %eax,-0xc(%ebp)
        ap++;
     857:	83 45 e8 04          	addl   $0x4,-0x18(%ebp)
        if(s == 0)
     85b:	83 7d f4 00          	cmpl   $0x0,-0xc(%ebp)
     85f:	75 27                	jne    888 <printf+0x11f>
          s = "(null)";
     861:	c7 45 f4 f2 11 00 00 	movl   $0x11f2,-0xc(%ebp)
        while(*s != 0){
     868:	eb 1e                	jmp    888 <printf+0x11f>
          putc(fd, *s);
     86a:	8b 45 f4             	mov    -0xc(%ebp),%eax
     86d:	0f b6 00             	movzbl (%eax),%eax
     870:	0f be c0             	movsbl %al,%eax
     873:	89 44 24 04          	mov    %eax,0x4(%esp)
     877:	8b 45 08             	mov    0x8(%ebp),%eax
     87a:	89 04 24             	mov    %eax,(%esp)
     87d:	e8 0a fe ff ff       	call   68c <putc>
          s++;
     882:	83 45 f4 01          	addl   $0x1,-0xc(%ebp)
     886:	eb 01                	jmp    889 <printf+0x120>
      } else if(c == 's'){
        s = (char*)*ap;
        ap++;
        if(s == 0)
          s = "(null)";
        while(*s != 0){
     888:	90                   	nop
     889:	8b 45 f4             	mov    -0xc(%ebp),%eax
     88c:	0f b6 00             	movzbl (%eax),%eax
     88f:	84 c0                	test   %al,%al
     891:	75 d7                	jne    86a <printf+0x101>
     893:	eb 68                	jmp    8fd <printf+0x194>
          putc(fd, *s);
          s++;
        }
      } else if(c == 'c'){
     895:	83 7d e4 63          	cmpl   $0x63,-0x1c(%ebp)
     899:	75 1d                	jne    8b8 <printf+0x14f>
        putc(fd, *ap);
     89b:	8b 45 e8             	mov    -0x18(%ebp),%eax
     89e:	8b 00                	mov    (%eax),%eax
     8a0:	0f be c0             	movsbl %al,%eax
     8a3:	89 44 24 04          	mov    %eax,0x4(%esp)
     8a7:	8b 45 08             	mov    0x8(%ebp),%eax
     8aa:	89 04 24             	mov    %eax,(%esp)
     8ad:	e8 da fd ff ff       	call   68c <putc>
        ap++;
     8b2:	83 45 e8 04          	addl   $0x4,-0x18(%ebp)
     8b6:	eb 45                	jmp    8fd <printf+0x194>
      } else if(c == '%'){
     8b8:	83 7d e4 25          	cmpl   $0x25,-0x1c(%ebp)
     8bc:	75 17                	jne    8d5 <printf+0x16c>
        putc(fd, c);
     8be:	8b 45 e4             	mov    -0x1c(%ebp),%eax
     8c1:	0f be c0             	movsbl %al,%eax
     8c4:	89 44 24 04          	mov    %eax,0x4(%esp)
     8c8:	8b 45 08             	mov    0x8(%ebp),%eax
     8cb:	89 04 24             	mov    %eax,(%esp)
     8ce:	e8 b9 fd ff ff       	call   68c <putc>
     8d3:	eb 28                	jmp    8fd <printf+0x194>
      } else {
        // Unknown % sequence.  Print it to draw attention.
        putc(fd, '%');
     8d5:	c7 44 24 04 25 00 00 	movl   $0x25,0x4(%esp)
     8dc:	00 
     8dd:	8b 45 08             	mov    0x8(%ebp),%eax
     8e0:	89 04 24             	mov    %eax,(%esp)
     8e3:	e8 a4 fd ff ff       	call   68c <putc>
        putc(fd, c);
     8e8:	8b 45 e4             	mov    -0x1c(%ebp),%eax
     8eb:	0f be c0             	movsbl %al,%eax
     8ee:	89 44 24 04          	mov    %eax,0x4(%esp)
     8f2:	8b 45 08             	mov    0x8(%ebp),%eax
     8f5:	89 04 24             	mov    %eax,(%esp)
     8f8:	e8 8f fd ff ff       	call   68c <putc>
      }
      state = 0;
     8fd:	c7 45 ec 00 00 00 00 	movl   $0x0,-0x14(%ebp)
  int c, i, state;
  uint *ap;

  state = 0;
  ap = (uint*)(void*)&fmt + 1;
  for(i = 0; fmt[i]; i++){
     904:	83 45 f0 01          	addl   $0x1,-0x10(%ebp)
     908:	8b 55 0c             	mov    0xc(%ebp),%edx
     90b:	8b 45 f0             	mov    -0x10(%ebp),%eax
     90e:	01 d0                	add    %edx,%eax
     910:	0f b6 00             	movzbl (%eax),%eax
     913:	84 c0                	test   %al,%al
     915:	0f 85 70 fe ff ff    	jne    78b <printf+0x22>
        putc(fd, c);
      }
      state = 0;
    }
  }
}
     91b:	c9                   	leave  
     91c:	c3                   	ret    
     91d:	66 90                	xchg   %ax,%ax
     91f:	90                   	nop

00000920 <free>:
static Header base;
static Header *freep;

void
free(void *ap)
{
     920:	55                   	push   %ebp
     921:	89 e5                	mov    %esp,%ebp
     923:	83 ec 10             	sub    $0x10,%esp
  Header *bp, *p;

  bp = (Header*)ap - 1;
     926:	8b 45 08             	mov    0x8(%ebp),%eax
     929:	83 e8 08             	sub    $0x8,%eax
     92c:	89 45 f8             	mov    %eax,-0x8(%ebp)
  for(p = freep; !(bp > p && bp < p->s.ptr); p = p->s.ptr)
     92f:	a1 08 17 00 00       	mov    0x1708,%eax
     934:	89 45 fc             	mov    %eax,-0x4(%ebp)
     937:	eb 24                	jmp    95d <free+0x3d>
    if(p >= p->s.ptr && (bp > p || bp < p->s.ptr))
     939:	8b 45 fc             	mov    -0x4(%ebp),%eax
     93c:	8b 00                	mov    (%eax),%eax
     93e:	3b 45 fc             	cmp    -0x4(%ebp),%eax
     941:	77 12                	ja     955 <free+0x35>
     943:	8b 45 f8             	mov    -0x8(%ebp),%eax
     946:	3b 45 fc             	cmp    -0x4(%ebp),%eax
     949:	77 24                	ja     96f <free+0x4f>
     94b:	8b 45 fc             	mov    -0x4(%ebp),%eax
     94e:	8b 00                	mov    (%eax),%eax
     950:	3b 45 f8             	cmp    -0x8(%ebp),%eax
     953:	77 1a                	ja     96f <free+0x4f>
free(void *ap)
{
  Header *bp, *p;

  bp = (Header*)ap - 1;
  for(p = freep; !(bp > p && bp < p->s.ptr); p = p->s.ptr)
     955:	8b 45 fc             	mov    -0x4(%ebp),%eax
     958:	8b 00                	mov    (%eax),%eax
     95a:	89 45 fc             	mov    %eax,-0x4(%ebp)
     95d:	8b 45 f8             	mov    -0x8(%ebp),%eax
     960:	3b 45 fc             	cmp    -0x4(%ebp),%eax
     963:	76 d4                	jbe    939 <free+0x19>
     965:	8b 45 fc             	mov    -0x4(%ebp),%eax
     968:	8b 00                	mov    (%eax),%eax
     96a:	3b 45 f8             	cmp    -0x8(%ebp),%eax
     96d:	76 ca                	jbe    939 <free+0x19>
    if(p >= p->s.ptr && (bp > p || bp < p->s.ptr))
      break;
  if(bp + bp->s.size == p->s.ptr){
     96f:	8b 45 f8             	mov    -0x8(%ebp),%eax
     972:	8b 40 04             	mov    0x4(%eax),%eax
     975:	8d 14 c5 00 00 00 00 	lea    0x0(,%eax,8),%edx
     97c:	8b 45 f8             	mov    -0x8(%ebp),%eax
     97f:	01 c2                	add    %eax,%edx
     981:	8b 45 fc             	mov    -0x4(%ebp),%eax
     984:	8b 00                	mov    (%eax),%eax
     986:	39 c2                	cmp    %eax,%edx
     988:	75 24                	jne    9ae <free+0x8e>
    bp->s.size += p->s.ptr->s.size;
     98a:	8b 45 f8             	mov    -0x8(%ebp),%eax
     98d:	8b 50 04             	mov    0x4(%eax),%edx
     990:	8b 45 fc             	mov    -0x4(%ebp),%eax
     993:	8b 00                	mov    (%eax),%eax
     995:	8b 40 04             	mov    0x4(%eax),%eax
     998:	01 c2                	add    %eax,%edx
     99a:	8b 45 f8             	mov    -0x8(%ebp),%eax
     99d:	89 50 04             	mov    %edx,0x4(%eax)
    bp->s.ptr = p->s.ptr->s.ptr;
     9a0:	8b 45 fc             	mov    -0x4(%ebp),%eax
     9a3:	8b 00                	mov    (%eax),%eax
     9a5:	8b 10                	mov    (%eax),%edx
     9a7:	8b 45 f8             	mov    -0x8(%ebp),%eax
     9aa:	89 10                	mov    %edx,(%eax)
     9ac:	eb 0a                	jmp    9b8 <free+0x98>
  } else
    bp->s.ptr = p->s.ptr;
     9ae:	8b 45 fc             	mov    -0x4(%ebp),%eax
     9b1:	8b 10                	mov    (%eax),%edx
     9b3:	8b 45 f8             	mov    -0x8(%ebp),%eax
     9b6:	89 10                	mov    %edx,(%eax)
  if(p + p->s.size == bp){
     9b8:	8b 45 fc             	mov    -0x4(%ebp),%eax
     9bb:	8b 40 04             	mov    0x4(%eax),%eax
     9be:	8d 14 c5 00 00 00 00 	lea    0x0(,%eax,8),%edx
     9c5:	8b 45 fc             	mov    -0x4(%ebp),%eax
     9c8:	01 d0                	add    %edx,%eax
     9ca:	3b 45 f8             	cmp    -0x8(%ebp),%eax
     9cd:	75 20                	jne    9ef <free+0xcf>
    p->s.size += bp->s.size;
     9cf:	8b 45 fc             	mov    -0x4(%ebp),%eax
     9d2:	8b 50 04             	mov    0x4(%eax),%edx
     9d5:	8b 45 f8             	mov    -0x8(%ebp),%eax
     9d8:	8b 40 04             	mov    0x4(%eax),%eax
     9db:	01 c2                	add    %eax,%edx
     9dd:	8b 45 fc             	mov    -0x4(%ebp),%eax
     9e0:	89 50 04             	mov    %edx,0x4(%eax)
    p->s.ptr = bp->s.ptr;
     9e3:	8b 45 f8             	mov    -0x8(%ebp),%eax
     9e6:	8b 10                	mov    (%eax),%edx
     9e8:	8b 45 fc             	mov    -0x4(%ebp),%eax
     9eb:	89 10                	mov    %edx,(%eax)
     9ed:	eb 08                	jmp    9f7 <free+0xd7>
  } else
    p->s.ptr = bp;
     9ef:	8b 45 fc             	mov    -0x4(%ebp),%eax
     9f2:	8b 55 f8             	mov    -0x8(%ebp),%edx
     9f5:	89 10                	mov    %edx,(%eax)
  freep = p;
     9f7:	8b 45 fc             	mov    -0x4(%ebp),%eax
     9fa:	a3 08 17 00 00       	mov    %eax,0x1708
}
     9ff:	c9                   	leave  
     a00:	c3                   	ret    

00000a01 <morecore>:

static Header*
morecore(uint nu)
{
     a01:	55                   	push   %ebp
     a02:	89 e5                	mov    %esp,%ebp
     a04:	83 ec 28             	sub    $0x28,%esp
  char *p;
  Header *hp;

  if(nu < 4096)
     a07:	81 7d 08 ff 0f 00 00 	cmpl   $0xfff,0x8(%ebp)
     a0e:	77 07                	ja     a17 <morecore+0x16>
    nu = 4096;
     a10:	c7 45 08 00 10 00 00 	movl   $0x1000,0x8(%ebp)
  p = sbrk(nu * sizeof(Header));
     a17:	8b 45 08             	mov    0x8(%ebp),%eax
     a1a:	c1 e0 03             	shl    $0x3,%eax
     a1d:	89 04 24             	mov    %eax,(%esp)
     a20:	e8 2f fc ff ff       	call   654 <sbrk>
     a25:	89 45 f4             	mov    %eax,-0xc(%ebp)
  if(p == (char*)-1)
     a28:	83 7d f4 ff          	cmpl   $0xffffffff,-0xc(%ebp)
     a2c:	75 07                	jne    a35 <morecore+0x34>
    return 0;
     a2e:	b8 00 00 00 00       	mov    $0x0,%eax
     a33:	eb 22                	jmp    a57 <morecore+0x56>
  hp = (Header*)p;
     a35:	8b 45 f4             	mov    -0xc(%ebp),%eax
     a38:	89 45 f0             	mov    %eax,-0x10(%ebp)
  hp->s.size = nu;
     a3b:	8b 45 f0             	mov    -0x10(%ebp),%eax
     a3e:	8b 55 08             	mov    0x8(%ebp),%edx
     a41:	89 50 04             	mov    %edx,0x4(%eax)
  free((void*)(hp + 1));
     a44:	8b 45 f0             	mov    -0x10(%ebp),%eax
     a47:	83 c0 08             	add    $0x8,%eax
     a4a:	89 04 24             	mov    %eax,(%esp)
     a4d:	e8 ce fe ff ff       	call   920 <free>
  return freep;
     a52:	a1 08 17 00 00       	mov    0x1708,%eax
}
     a57:	c9                   	leave  
     a58:	c3                   	ret    

00000a59 <malloc>:

void*
malloc(uint nbytes)
{
     a59:	55                   	push   %ebp
     a5a:	89 e5                	mov    %esp,%ebp
     a5c:	83 ec 28             	sub    $0x28,%esp
  Header *p, *prevp;
  uint nunits;

  nunits = (nbytes + sizeof(Header) - 1)/sizeof(Header) + 1;
     a5f:	8b 45 08             	mov    0x8(%ebp),%eax
     a62:	83 c0 07             	add    $0x7,%eax
     a65:	c1 e8 03             	shr    $0x3,%eax
     a68:	83 c0 01             	add    $0x1,%eax
     a6b:	89 45 ec             	mov    %eax,-0x14(%ebp)
  if((prevp = freep) == 0){
     a6e:	a1 08 17 00 00       	mov    0x1708,%eax
     a73:	89 45 f0             	mov    %eax,-0x10(%ebp)
     a76:	83 7d f0 00          	cmpl   $0x0,-0x10(%ebp)
     a7a:	75 23                	jne    a9f <malloc+0x46>
    base.s.ptr = freep = prevp = &base;
     a7c:	c7 45 f0 00 17 00 00 	movl   $0x1700,-0x10(%ebp)
     a83:	8b 45 f0             	mov    -0x10(%ebp),%eax
     a86:	a3 08 17 00 00       	mov    %eax,0x1708
     a8b:	a1 08 17 00 00       	mov    0x1708,%eax
     a90:	a3 00 17 00 00       	mov    %eax,0x1700
    base.s.size = 0;
     a95:	c7 05 04 17 00 00 00 	movl   $0x0,0x1704
     a9c:	00 00 00 
  }
  for(p = prevp->s.ptr; ; prevp = p, p = p->s.ptr){
     a9f:	8b 45 f0             	mov    -0x10(%ebp),%eax
     aa2:	8b 00                	mov    (%eax),%eax
     aa4:	89 45 f4             	mov    %eax,-0xc(%ebp)
    if(p->s.size >= nunits){
     aa7:	8b 45 f4             	mov    -0xc(%ebp),%eax
     aaa:	8b 40 04             	mov    0x4(%eax),%eax
     aad:	3b 45 ec             	cmp    -0x14(%ebp),%eax
     ab0:	72 4d                	jb     aff <malloc+0xa6>
      if(p->s.size == nunits)
     ab2:	8b 45 f4             	mov    -0xc(%ebp),%eax
     ab5:	8b 40 04             	mov    0x4(%eax),%eax
     ab8:	3b 45 ec             	cmp    -0x14(%ebp),%eax
     abb:	75 0c                	jne    ac9 <malloc+0x70>
        prevp->s.ptr = p->s.ptr;
     abd:	8b 45 f4             	mov    -0xc(%ebp),%eax
     ac0:	8b 10                	mov    (%eax),%edx
     ac2:	8b 45 f0             	mov    -0x10(%ebp),%eax
     ac5:	89 10                	mov    %edx,(%eax)
     ac7:	eb 26                	jmp    aef <malloc+0x96>
      else {
        p->s.size -= nunits;
     ac9:	8b 45 f4             	mov    -0xc(%ebp),%eax
     acc:	8b 40 04             	mov    0x4(%eax),%eax
     acf:	89 c2                	mov    %eax,%edx
     ad1:	2b 55 ec             	sub    -0x14(%ebp),%edx
     ad4:	8b 45 f4             	mov    -0xc(%ebp),%eax
     ad7:	89 50 04             	mov    %edx,0x4(%eax)
        p += p->s.size;
     ada:	8b 45 f4             	mov    -0xc(%ebp),%eax
     add:	8b 40 04             	mov    0x4(%eax),%eax
     ae0:	c1 e0 03             	shl    $0x3,%eax
     ae3:	01 45 f4             	add    %eax,-0xc(%ebp)
        p->s.size = nunits;
     ae6:	8b 45 f4             	mov    -0xc(%ebp),%eax
     ae9:	8b 55 ec             	mov    -0x14(%ebp),%edx
     aec:	89 50 04             	mov    %edx,0x4(%eax)
      }
      freep = prevp;
     aef:	8b 45 f0             	mov    -0x10(%ebp),%eax
     af2:	a3 08 17 00 00       	mov    %eax,0x1708
      return (void*)(p + 1);
     af7:	8b 45 f4             	mov    -0xc(%ebp),%eax
     afa:	83 c0 08             	add    $0x8,%eax
     afd:	eb 38                	jmp    b37 <malloc+0xde>
    }
    if(p == freep)
     aff:	a1 08 17 00 00       	mov    0x1708,%eax
     b04:	39 45 f4             	cmp    %eax,-0xc(%ebp)
     b07:	75 1b                	jne    b24 <malloc+0xcb>
      if((p = morecore(nunits)) == 0)
     b09:	8b 45 ec             	mov    -0x14(%ebp),%eax
     b0c:	89 04 24             	mov    %eax,(%esp)
     b0f:	e8 ed fe ff ff       	call   a01 <morecore>
     b14:	89 45 f4             	mov    %eax,-0xc(%ebp)
     b17:	83 7d f4 00          	cmpl   $0x0,-0xc(%ebp)
     b1b:	75 07                	jne    b24 <malloc+0xcb>
        return 0;
     b1d:	b8 00 00 00 00       	mov    $0x0,%eax
     b22:	eb 13                	jmp    b37 <malloc+0xde>
  nunits = (nbytes + sizeof(Header) - 1)/sizeof(Header) + 1;
  if((prevp = freep) == 0){
    base.s.ptr = freep = prevp = &base;
    base.s.size = 0;
  }
  for(p = prevp->s.ptr; ; prevp = p, p = p->s.ptr){
     b24:	8b 45 f4             	mov    -0xc(%ebp),%eax
     b27:	89 45 f0             	mov    %eax,-0x10(%ebp)
     b2a:	8b 45 f4             	mov    -0xc(%ebp),%eax
     b2d:	8b 00                	mov    (%eax),%eax
     b2f:	89 45 f4             	mov    %eax,-0xc(%ebp)
      return (void*)(p + 1);
    }
    if(p == freep)
      if((p = morecore(nunits)) == 0)
        return 0;
  }
     b32:	e9 70 ff ff ff       	jmp    aa7 <malloc+0x4e>
}
     b37:	c9                   	leave  
     b38:	c3                   	ret    
     b39:	66 90                	xchg   %ax,%ax
     b3b:	90                   	nop

00000b3c <uthread_init>:
int c_thread = 0;

// task 2.2

void uthread_init()
{
     b3c:	55                   	push   %ebp
     b3d:	89 e5                	mov    %esp,%ebp
     b3f:	83 ec 28             	sub    $0x28,%esp

	int i;
	ttable[0].tid = 0;
     b42:	c7 05 20 1b 00 00 00 	movl   $0x0,0x1b20
     b49:	00 00 00 
	STORE_ESP(ttable[0].esp);
     b4c:	89 e0                	mov    %esp,%eax
     b4e:	a3 24 1b 00 00       	mov    %eax,0x1b24
	STORE_EBP(ttable[0].ebp);
     b53:	89 e8                	mov    %ebp,%eax
     b55:	a3 28 1b 00 00       	mov    %eax,0x1b28
	ttable[0].state = T_RUNNING;
     b5a:	c7 05 30 1b 00 00 01 	movl   $0x1,0x1b30
     b61:	00 00 00 
	ttable[0].wait_num = 0;
     b64:	c7 05 34 1c 00 00 00 	movl   $0x0,0x1c34
     b6b:	00 00 00 
	//initialize all other slots to FREE and assign TIDs for future use
	for (i = 1; i < MAX_THREAD; i ++)
     b6e:	c7 45 f4 01 00 00 00 	movl   $0x1,-0xc(%ebp)
     b75:	eb 2c                	jmp    ba3 <uthread_init+0x67>
	{
		ttable[i].tid = i;
     b77:	8b 45 f4             	mov    -0xc(%ebp),%eax
     b7a:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
     b80:	8d 90 20 1b 00 00    	lea    0x1b20(%eax),%edx
     b86:	8b 45 f4             	mov    -0xc(%ebp),%eax
     b89:	89 02                	mov    %eax,(%edx)
		ttable[i].state = T_FREE;
     b8b:	8b 45 f4             	mov    -0xc(%ebp),%eax
     b8e:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
     b94:	05 30 1b 00 00       	add    $0x1b30,%eax
     b99:	c7 00 00 00 00 00    	movl   $0x0,(%eax)
	STORE_ESP(ttable[0].esp);
	STORE_EBP(ttable[0].ebp);
	ttable[0].state = T_RUNNING;
	ttable[0].wait_num = 0;
	//initialize all other slots to FREE and assign TIDs for future use
	for (i = 1; i < MAX_THREAD; i ++)
     b9f:	83 45 f4 01          	addl   $0x1,-0xc(%ebp)
     ba3:	83 7d f4 3f          	cmpl   $0x3f,-0xc(%ebp)
     ba7:	7e ce                	jle    b77 <uthread_init+0x3b>
	{
		ttable[i].tid = i;
		ttable[i].state = T_FREE;
	}
	signal(SIGALRM, uthread_yield);
     ba9:	c7 44 24 04 2f 0e 00 	movl   $0xe2f,0x4(%esp)
     bb0:	00 
     bb1:	c7 04 24 0e 00 00 00 	movl   $0xe,(%esp)
     bb8:	e8 af fa ff ff       	call   66c <signal>
	alarm(THREAD_QUANTA);
     bbd:	c7 04 24 05 00 00 00 	movl   $0x5,(%esp)
     bc4:	e8 b3 fa ff ff       	call   67c <alarm>
}
     bc9:	c9                   	leave  
     bca:	c3                   	ret    

00000bcb <uthread_create>:

// task 2.3

int uthread_create(void (*start_func)(void *), void*arg)
{
     bcb:	55                   	push   %ebp
     bcc:	89 e5                	mov    %esp,%ebp
     bce:	83 ec 28             	sub    $0x28,%esp
	int i;
	int ticks;
	asm("pusha");
     bd1:	60                   	pusha  
	ticks = getTicks();
     bd2:	e8 ad fa ff ff       	call   684 <getTicks>
     bd7:	89 45 f0             	mov    %eax,-0x10(%ebp)
	alarm(0);
     bda:	c7 04 24 00 00 00 00 	movl   $0x0,(%esp)
     be1:	e8 96 fa ff ff       	call   67c <alarm>
	asm("popa");
     be6:	61                   	popa   
	for (i = 0; i < MAX_THREAD; i++)
     be7:	c7 45 f4 00 00 00 00 	movl   $0x0,-0xc(%ebp)
     bee:	e9 02 01 00 00       	jmp    cf5 <uthread_create+0x12a>
	{
		if (ttable[i].state == T_FREE)
     bf3:	8b 45 f4             	mov    -0xc(%ebp),%eax
     bf6:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
     bfc:	05 30 1b 00 00       	add    $0x1b30,%eax
     c01:	8b 00                	mov    (%eax),%eax
     c03:	85 c0                	test   %eax,%eax
     c05:	0f 85 e6 00 00 00    	jne    cf1 <uthread_create+0x126>
		{	
			//allocate a stack for the new thread
			if ((ttable[i].stack = malloc(STACK_SIZE)) < 0)
     c0b:	c7 04 24 00 10 00 00 	movl   $0x1000,(%esp)
     c12:	e8 42 fe ff ff       	call   a59 <malloc>
     c17:	8b 55 f4             	mov    -0xc(%ebp),%edx
     c1a:	69 d2 18 01 00 00    	imul   $0x118,%edx,%edx
     c20:	81 c2 20 1b 00 00    	add    $0x1b20,%edx
     c26:	89 42 0c             	mov    %eax,0xc(%edx)
			{
				alarm(ticks);
				return -1;
			}
			LOAD_ESP(ttable[i].stack + STACK_SIZE);
     c29:	8b 45 f4             	mov    -0xc(%ebp),%eax
     c2c:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
     c32:	05 20 1b 00 00       	add    $0x1b20,%eax
     c37:	8b 40 0c             	mov    0xc(%eax),%eax
     c3a:	05 00 10 00 00       	add    $0x1000,%eax
     c3f:	89 c4                	mov    %eax,%esp
			PUSH(arg);
     c41:	8b 45 0c             	mov    0xc(%ebp),%eax
     c44:	89 c7                	mov    %eax,%edi
     c46:	57                   	push   %edi
			PUSH(uthread_exit);
     c47:	b8 b5 0e 00 00       	mov    $0xeb5,%eax
     c4c:	89 c7                	mov    %eax,%edi
     c4e:	57                   	push   %edi
			PUSH(start_func);
     c4f:	8b 45 08             	mov    0x8(%ebp),%eax
     c52:	89 c7                	mov    %eax,%edi
     c54:	57                   	push   %edi
			//added for the first "pop ebp"
			PUSH(0);
     c55:	b8 00 00 00 00       	mov    $0x0,%eax
     c5a:	89 c7                	mov    %eax,%edi
     c5c:	57                   	push   %edi
			STORE_ESP(ttable[i].ebp);
     c5d:	89 e0                	mov    %esp,%eax
     c5f:	8b 55 f4             	mov    -0xc(%ebp),%edx
     c62:	69 d2 18 01 00 00    	imul   $0x118,%edx,%edx
     c68:	81 c2 20 1b 00 00    	add    $0x1b20,%edx
     c6e:	89 42 08             	mov    %eax,0x8(%edx)
			ttable[i].esp = ttable[i].ebp;
     c71:	8b 45 f4             	mov    -0xc(%ebp),%eax
     c74:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
     c7a:	05 20 1b 00 00       	add    $0x1b20,%eax
     c7f:	8b 40 08             	mov    0x8(%eax),%eax
     c82:	8b 55 f4             	mov    -0xc(%ebp),%edx
     c85:	69 d2 18 01 00 00    	imul   $0x118,%edx,%edx
     c8b:	81 c2 20 1b 00 00    	add    $0x1b20,%edx
     c91:	89 42 04             	mov    %eax,0x4(%edx)
			//set esp to current thread's esp
			LOAD_ESP(ttable[c_thread].esp);
     c94:	a1 0c 17 00 00       	mov    0x170c,%eax
     c99:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
     c9f:	05 20 1b 00 00       	add    $0x1b20,%eax
     ca4:	8b 40 04             	mov    0x4(%eax),%eax
     ca7:	89 c4                	mov    %eax,%esp
			ttable[i].state = T_RUNNABLE;
     ca9:	8b 45 f4             	mov    -0xc(%ebp),%eax
     cac:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
     cb2:	05 30 1b 00 00       	add    $0x1b30,%eax
     cb7:	c7 00 02 00 00 00    	movl   $0x2,(%eax)
			ttable[i].wait_num = 0;
     cbd:	8b 45 f4             	mov    -0xc(%ebp),%eax
     cc0:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
     cc6:	05 30 1c 00 00       	add    $0x1c30,%eax
     ccb:	c7 40 04 00 00 00 00 	movl   $0x0,0x4(%eax)
			asm("pusha");
     cd2:	60                   	pusha  
			alarm(ticks);
     cd3:	8b 45 f0             	mov    -0x10(%ebp),%eax
     cd6:	89 04 24             	mov    %eax,(%esp)
     cd9:	e8 9e f9 ff ff       	call   67c <alarm>
			asm("popa");
     cde:	61                   	popa   
			return ttable[i].tid;
     cdf:	8b 45 f4             	mov    -0xc(%ebp),%eax
     ce2:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
     ce8:	05 20 1b 00 00       	add    $0x1b20,%eax
     ced:	8b 00                	mov    (%eax),%eax
     cef:	eb 1e                	jmp    d0f <uthread_create+0x144>
	int ticks;
	asm("pusha");
	ticks = getTicks();
	alarm(0);
	asm("popa");
	for (i = 0; i < MAX_THREAD; i++)
     cf1:	83 45 f4 01          	addl   $0x1,-0xc(%ebp)
     cf5:	83 7d f4 3f          	cmpl   $0x3f,-0xc(%ebp)
     cf9:	0f 8e f4 fe ff ff    	jle    bf3 <uthread_create+0x28>
			asm("popa");
			return ttable[i].tid;
			
		}
	}
	alarm(ticks);
     cff:	8b 45 f0             	mov    -0x10(%ebp),%eax
     d02:	89 04 24             	mov    %eax,(%esp)
     d05:	e8 72 f9 ff ff       	call   67c <alarm>
	//failed - no free thread to use
	return -1;
     d0a:	b8 ff ff ff ff       	mov    $0xffffffff,%eax
}
     d0f:	c9                   	leave  
     d10:	c3                   	ret    

00000d11 <safe_exit>:

// task 2.4


void safe_exit()
{
     d11:	55                   	push   %ebp
     d12:	89 e5                	mov    %esp,%ebp
     d14:	83 ec 28             	sub    $0x28,%esp
     d17:	eb 01                	jmp    d1a <safe_exit+0x9>
			}
		}
		if (tid == MAX_THREAD){
			exit();
		}
	}
     d19:	90                   	nop
void safe_exit()
{
	int tid;
	while (1)
	{
		for (tid = 1; tid< MAX_THREAD; tid++)
     d1a:	c7 45 f4 01 00 00 00 	movl   $0x1,-0xc(%ebp)
     d21:	eb 25                	jmp    d48 <safe_exit+0x37>
		{
			if (ttable[tid].state != T_FREE){
     d23:	8b 45 f4             	mov    -0xc(%ebp),%eax
     d26:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
     d2c:	05 30 1b 00 00       	add    $0x1b30,%eax
     d31:	8b 00                	mov    (%eax),%eax
     d33:	85 c0                	test   %eax,%eax
     d35:	74 0d                	je     d44 <safe_exit+0x33>
				uthread_join(tid);
     d37:	8b 45 f4             	mov    -0xc(%ebp),%eax
     d3a:	89 04 24             	mov    %eax,(%esp)
     d3d:	e8 1d 02 00 00       	call   f5f <uthread_join>
				break;
     d42:	eb 0a                	jmp    d4e <safe_exit+0x3d>
void safe_exit()
{
	int tid;
	while (1)
	{
		for (tid = 1; tid< MAX_THREAD; tid++)
     d44:	83 45 f4 01          	addl   $0x1,-0xc(%ebp)
     d48:	83 7d f4 3f          	cmpl   $0x3f,-0xc(%ebp)
     d4c:	7e d5                	jle    d23 <safe_exit+0x12>
			if (ttable[tid].state != T_FREE){
				uthread_join(tid);
				break;
			}
		}
		if (tid == MAX_THREAD){
     d4e:	83 7d f4 40          	cmpl   $0x40,-0xc(%ebp)
     d52:	75 c5                	jne    d19 <safe_exit+0x8>
			exit();
     d54:	e8 73 f8 ff ff       	call   5cc <exit>

00000d59 <uthread_switch>:
		}
	}
}

void uthread_switch()
{
     d59:	55                   	push   %ebp
     d5a:	89 e5                	mov    %esp,%ebp
     d5c:	83 ec 28             	sub    $0x28,%esp
	int i;
	int n_thread = (c_thread + 1) % MAX_THREAD;
     d5f:	a1 0c 17 00 00       	mov    0x170c,%eax
     d64:	8d 50 01             	lea    0x1(%eax),%edx
     d67:	89 d0                	mov    %edx,%eax
     d69:	c1 f8 1f             	sar    $0x1f,%eax
     d6c:	c1 e8 1a             	shr    $0x1a,%eax
     d6f:	01 c2                	add    %eax,%edx
     d71:	83 e2 3f             	and    $0x3f,%edx
     d74:	89 d1                	mov    %edx,%ecx
     d76:	29 c1                	sub    %eax,%ecx
     d78:	89 c8                	mov    %ecx,%eax
     d7a:	89 45 f0             	mov    %eax,-0x10(%ebp)

	//finding a runnable thread
	for (i = 0; ttable[n_thread].state != T_RUNNABLE && i < MAX_THREAD; i++)
     d7d:	c7 45 f4 00 00 00 00 	movl   $0x0,-0xc(%ebp)
     d84:	eb 20                	jmp    da6 <uthread_switch+0x4d>
	{
		n_thread = (n_thread + 1) % MAX_THREAD;
     d86:	8b 45 f0             	mov    -0x10(%ebp),%eax
     d89:	8d 50 01             	lea    0x1(%eax),%edx
     d8c:	89 d0                	mov    %edx,%eax
     d8e:	c1 f8 1f             	sar    $0x1f,%eax
     d91:	c1 e8 1a             	shr    $0x1a,%eax
     d94:	01 c2                	add    %eax,%edx
     d96:	83 e2 3f             	and    $0x3f,%edx
     d99:	89 d1                	mov    %edx,%ecx
     d9b:	29 c1                	sub    %eax,%ecx
     d9d:	89 c8                	mov    %ecx,%eax
     d9f:	89 45 f0             	mov    %eax,-0x10(%ebp)
{
	int i;
	int n_thread = (c_thread + 1) % MAX_THREAD;

	//finding a runnable thread
	for (i = 0; ttable[n_thread].state != T_RUNNABLE && i < MAX_THREAD; i++)
     da2:	83 45 f4 01          	addl   $0x1,-0xc(%ebp)
     da6:	8b 45 f0             	mov    -0x10(%ebp),%eax
     da9:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
     daf:	05 30 1b 00 00       	add    $0x1b30,%eax
     db4:	8b 00                	mov    (%eax),%eax
     db6:	83 f8 02             	cmp    $0x2,%eax
     db9:	74 06                	je     dc1 <uthread_switch+0x68>
     dbb:	83 7d f4 3f          	cmpl   $0x3f,-0xc(%ebp)
     dbf:	7e c5                	jle    d86 <uthread_switch+0x2d>
	{
		n_thread = (n_thread + 1) % MAX_THREAD;
	}
	STORE_ESP(ttable[c_thread].esp);
     dc1:	8b 15 0c 17 00 00    	mov    0x170c,%edx
     dc7:	89 e0                	mov    %esp,%eax
     dc9:	69 d2 18 01 00 00    	imul   $0x118,%edx,%edx
     dcf:	81 c2 20 1b 00 00    	add    $0x1b20,%edx
     dd5:	89 42 04             	mov    %eax,0x4(%edx)
	STORE_EBP(ttable[c_thread].ebp);
     dd8:	8b 15 0c 17 00 00    	mov    0x170c,%edx
     dde:	89 e8                	mov    %ebp,%eax
     de0:	69 d2 18 01 00 00    	imul   $0x118,%edx,%edx
     de6:	81 c2 20 1b 00 00    	add    $0x1b20,%edx
     dec:	89 42 08             	mov    %eax,0x8(%edx)
	c_thread = n_thread;
     def:	8b 45 f0             	mov    -0x10(%ebp),%eax
     df2:	a3 0c 17 00 00       	mov    %eax,0x170c
	LOAD_EBP(ttable[c_thread].ebp);
     df7:	a1 0c 17 00 00       	mov    0x170c,%eax
     dfc:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
     e02:	05 20 1b 00 00       	add    $0x1b20,%eax
     e07:	8b 40 08             	mov    0x8(%eax),%eax
     e0a:	89 c5                	mov    %eax,%ebp
	LOAD_ESP(ttable[c_thread].esp);
     e0c:	a1 0c 17 00 00       	mov    0x170c,%eax
     e11:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
     e17:	05 20 1b 00 00       	add    $0x1b20,%eax
     e1c:	8b 40 04             	mov    0x4(%eax),%eax
     e1f:	89 c4                	mov    %eax,%esp
	alarm(THREAD_QUANTA);
     e21:	c7 04 24 05 00 00 00 	movl   $0x5,(%esp)
     e28:	e8 4f f8 ff ff       	call   67c <alarm>
}
     e2d:	c9                   	leave  
     e2e:	c3                   	ret    

00000e2f <uthread_yield>:

void uthread_yield()
{
     e2f:	55                   	push   %ebp
     e30:	89 e5                	mov    %esp,%ebp
     e32:	83 ec 18             	sub    $0x18,%esp
	//store registers on stack
	asm("pusha");
     e35:	60                   	pusha  
	alarm(0);
     e36:	c7 04 24 00 00 00 00 	movl   $0x0,(%esp)
     e3d:	e8 3a f8 ff ff       	call   67c <alarm>
	ttable[c_thread].state = T_RUNNABLE;
     e42:	a1 0c 17 00 00       	mov    0x170c,%eax
     e47:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
     e4d:	05 30 1b 00 00       	add    $0x1b30,%eax
     e52:	c7 00 02 00 00 00    	movl   $0x2,(%eax)
	//change current thread
	uthread_switch();
     e58:	e8 fc fe ff ff       	call   d59 <uthread_switch>
	asm("popa");
     e5d:	61                   	popa   
}
     e5e:	c9                   	leave  
     e5f:	c3                   	ret    

00000e60 <uthread_awake>:

// task 2.5

void uthread_awake()
{
     e60:	55                   	push   %ebp
     e61:	89 e5                	mov    %esp,%ebp
     e63:	83 ec 10             	sub    $0x10,%esp
	int i;
	for (i = 0; i < ttable[c_thread].wait_num; i++)
     e66:	c7 45 fc 00 00 00 00 	movl   $0x0,-0x4(%ebp)
     e6d:	eb 2c                	jmp    e9b <uthread_awake+0x3b>
		ttable[ttable[c_thread].waiting[i]].state = T_RUNNABLE;
     e6f:	a1 0c 17 00 00       	mov    0x170c,%eax
     e74:	6b d0 46             	imul   $0x46,%eax,%edx
     e77:	8b 45 fc             	mov    -0x4(%ebp),%eax
     e7a:	01 d0                	add    %edx,%eax
     e7c:	83 c0 04             	add    $0x4,%eax
     e7f:	8b 04 85 24 1b 00 00 	mov    0x1b24(,%eax,4),%eax
     e86:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
     e8c:	05 30 1b 00 00       	add    $0x1b30,%eax
     e91:	c7 00 02 00 00 00    	movl   $0x2,(%eax)
// task 2.5

void uthread_awake()
{
	int i;
	for (i = 0; i < ttable[c_thread].wait_num; i++)
     e97:	83 45 fc 01          	addl   $0x1,-0x4(%ebp)
     e9b:	a1 0c 17 00 00       	mov    0x170c,%eax
     ea0:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
     ea6:	05 30 1c 00 00       	add    $0x1c30,%eax
     eab:	8b 40 04             	mov    0x4(%eax),%eax
     eae:	3b 45 fc             	cmp    -0x4(%ebp),%eax
     eb1:	7f bc                	jg     e6f <uthread_awake+0xf>
		ttable[ttable[c_thread].waiting[i]].state = T_RUNNABLE;
}
     eb3:	c9                   	leave  
     eb4:	c3                   	ret    

00000eb5 <uthread_exit>:

void uthread_exit()
{
     eb5:	55                   	push   %ebp
     eb6:	89 e5                	mov    %esp,%ebp
     eb8:	83 ec 18             	sub    $0x18,%esp
	asm("pusha");
     ebb:	60                   	pusha  
	alarm(0);
     ebc:	c7 04 24 00 00 00 00 	movl   $0x0,(%esp)
     ec3:	e8 b4 f7 ff ff       	call   67c <alarm>
	asm("popa");
     ec8:	61                   	popa   
	ttable[c_thread].state = T_FREE;
     ec9:	a1 0c 17 00 00       	mov    0x170c,%eax
     ece:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
     ed4:	05 30 1b 00 00       	add    $0x1b30,%eax
     ed9:	c7 00 00 00 00 00    	movl   $0x0,(%eax)
	if (ttable[c_thread].tid != 0)
     edf:	a1 0c 17 00 00       	mov    0x170c,%eax
     ee4:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
     eea:	05 20 1b 00 00       	add    $0x1b20,%eax
     eef:	8b 00                	mov    (%eax),%eax
     ef1:	85 c0                	test   %eax,%eax
     ef3:	74 1d                	je     f12 <uthread_exit+0x5d>
		free(ttable[c_thread].stack);
     ef5:	a1 0c 17 00 00       	mov    0x170c,%eax
     efa:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
     f00:	05 20 1b 00 00       	add    $0x1b20,%eax
     f05:	8b 40 0c             	mov    0xc(%eax),%eax
     f08:	89 04 24             	mov    %eax,(%esp)
     f0b:	e8 10 fa ff ff       	call   920 <free>
     f10:	eb 05                	jmp    f17 <uthread_exit+0x62>
	else
		safe_exit();
     f12:	e8 fa fd ff ff       	call   d11 <safe_exit>
	uthread_awake();
     f17:	e8 44 ff ff ff       	call   e60 <uthread_awake>
	uthread_switch();
     f1c:	e8 38 fe ff ff       	call   d59 <uthread_switch>
	asm("popa");
     f21:	61                   	popa   
}
     f22:	c9                   	leave  
     f23:	c3                   	ret    

00000f24 <uthread_self>:

// task 2.6

int uthread_self()
{
     f24:	55                   	push   %ebp
     f25:	89 e5                	mov    %esp,%ebp
	return c_thread;
     f27:	a1 0c 17 00 00       	mov    0x170c,%eax
}
     f2c:	5d                   	pop    %ebp
     f2d:	c3                   	ret    

00000f2e <uthread_sleep>:

// task 2.7

void uthread_sleep()
{
     f2e:	55                   	push   %ebp
     f2f:	89 e5                	mov    %esp,%ebp
     f31:	83 ec 18             	sub    $0x18,%esp
	asm("pusha");
     f34:	60                   	pusha  
	alarm(0);
     f35:	c7 04 24 00 00 00 00 	movl   $0x0,(%esp)
     f3c:	e8 3b f7 ff ff       	call   67c <alarm>
	ttable[c_thread].state = T_SLEEPING;
     f41:	a1 0c 17 00 00       	mov    0x170c,%eax
     f46:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
     f4c:	05 30 1b 00 00       	add    $0x1b30,%eax
     f51:	c7 00 03 00 00 00    	movl   $0x3,(%eax)
	uthread_switch();
     f57:	e8 fd fd ff ff       	call   d59 <uthread_switch>
	asm("popa");
     f5c:	61                   	popa   
}
     f5d:	c9                   	leave  
     f5e:	c3                   	ret    

00000f5f <uthread_join>:

int uthread_join(int tid)
{
     f5f:	55                   	push   %ebp
     f60:	89 e5                	mov    %esp,%ebp
     f62:	53                   	push   %ebx
     f63:	83 ec 24             	sub    $0x24,%esp

	int ticks;
	asm("pusha");
     f66:	60                   	pusha  
	ticks = getTicks();
     f67:	e8 18 f7 ff ff       	call   684 <getTicks>
     f6c:	89 45 f4             	mov    %eax,-0xc(%ebp)
	alarm(0);
     f6f:	c7 04 24 00 00 00 00 	movl   $0x0,(%esp)
     f76:	e8 01 f7 ff ff       	call   67c <alarm>
	asm("popa");
     f7b:	61                   	popa   
	if (ttable[tid].state != T_FREE)
     f7c:	8b 45 08             	mov    0x8(%ebp),%eax
     f7f:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
     f85:	05 30 1b 00 00       	add    $0x1b30,%eax
     f8a:	8b 00                	mov    (%eax),%eax
     f8c:	85 c0                	test   %eax,%eax
     f8e:	74 5e                	je     fee <uthread_join+0x8f>
	{
		//adding current thread to tid waiting list and going to sleep.
		ttable[tid].waiting[ttable[tid].wait_num++] = ttable[c_thread].tid;
     f90:	8b 45 08             	mov    0x8(%ebp),%eax
     f93:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
     f99:	05 10 01 00 00       	add    $0x110,%eax
     f9e:	05 20 1b 00 00       	add    $0x1b20,%eax
     fa3:	8d 48 04             	lea    0x4(%eax),%ecx
     fa6:	8b 45 08             	mov    0x8(%ebp),%eax
     fa9:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
     faf:	05 30 1c 00 00       	add    $0x1c30,%eax
     fb4:	8b 40 04             	mov    0x4(%eax),%eax
     fb7:	8b 15 0c 17 00 00    	mov    0x170c,%edx
     fbd:	69 d2 18 01 00 00    	imul   $0x118,%edx,%edx
     fc3:	81 c2 20 1b 00 00    	add    $0x1b20,%edx
     fc9:	8b 12                	mov    (%edx),%edx
     fcb:	8b 5d 08             	mov    0x8(%ebp),%ebx
     fce:	6b db 46             	imul   $0x46,%ebx,%ebx
     fd1:	01 c3                	add    %eax,%ebx
     fd3:	83 c3 04             	add    $0x4,%ebx
     fd6:	89 14 9d 24 1b 00 00 	mov    %edx,0x1b24(,%ebx,4)
     fdd:	83 c0 01             	add    $0x1,%eax
     fe0:	89 01                	mov    %eax,(%ecx)
		uthread_sleep();
     fe2:	e8 47 ff ff ff       	call   f2e <uthread_sleep>
		return 0;
     fe7:	b8 00 00 00 00       	mov    $0x0,%eax
     fec:	eb 12                	jmp    1000 <uthread_join+0xa1>
	}
	asm("pusha");
     fee:	60                   	pusha  
	alarm(ticks);
     fef:	8b 45 f4             	mov    -0xc(%ebp),%eax
     ff2:	89 04 24             	mov    %eax,(%esp)
     ff5:	e8 82 f6 ff ff       	call   67c <alarm>
	asm("popa");
     ffa:	61                   	popa   
	return -1;
     ffb:	b8 ff ff ff ff       	mov    $0xffffffff,%eax
}
    1000:	83 c4 24             	add    $0x24,%esp
    1003:	5b                   	pop    %ebx
    1004:	5d                   	pop    %ebp
    1005:	c3                   	ret    

00001006 <queue_init>:

void queue_init(struct tqueue *q)
{
    1006:	55                   	push   %ebp
    1007:	89 e5                	mov    %esp,%ebp
	q->head = 0;
    1009:	8b 45 08             	mov    0x8(%ebp),%eax
    100c:	c7 80 00 01 00 00 00 	movl   $0x0,0x100(%eax)
    1013:	00 00 00 
	q->tail = 0;
    1016:	8b 45 08             	mov    0x8(%ebp),%eax
    1019:	c7 80 04 01 00 00 00 	movl   $0x0,0x104(%eax)
    1020:	00 00 00 
}
    1023:	5d                   	pop    %ebp
    1024:	c3                   	ret    

00001025 <dequeue>:

struct uthread* dequeue(struct binary_semaphore* semaphore)
{
    1025:	55                   	push   %ebp
    1026:	89 e5                	mov    %esp,%ebp
    1028:	57                   	push   %edi
    1029:	56                   	push   %esi
    102a:	53                   	push   %ebx
	if (semaphore->queue->head == semaphore->queue->tail)
    102b:	8b 45 08             	mov    0x8(%ebp),%eax
    102e:	8b 00                	mov    (%eax),%eax
    1030:	8b 90 00 01 00 00    	mov    0x100(%eax),%edx
    1036:	8b 45 08             	mov    0x8(%ebp),%eax
    1039:	8b 00                	mov    (%eax),%eax
    103b:	8b 80 04 01 00 00    	mov    0x104(%eax),%eax
    1041:	39 c2                	cmp    %eax,%edx
    1043:	75 07                	jne    104c <dequeue+0x27>
		return 0;
    1045:	b9 00 00 00 00       	mov    $0x0,%ecx
    104a:	eb 31                	jmp    107d <dequeue+0x58>
	return semaphore->queue->uthreads[semaphore->queue->tail++ % MAX_THREAD];
    104c:	8b 45 08             	mov    0x8(%ebp),%eax
    104f:	8b 18                	mov    (%eax),%ebx
    1051:	8b 45 08             	mov    0x8(%ebp),%eax
    1054:	8b 10                	mov    (%eax),%edx
    1056:	8b 82 04 01 00 00    	mov    0x104(%edx),%eax
    105c:	89 c1                	mov    %eax,%ecx
    105e:	c1 f9 1f             	sar    $0x1f,%ecx
    1061:	c1 e9 1a             	shr    $0x1a,%ecx
    1064:	8d 34 08             	lea    (%eax,%ecx,1),%esi
    1067:	83 e6 3f             	and    $0x3f,%esi
    106a:	89 f7                	mov    %esi,%edi
    106c:	29 cf                	sub    %ecx,%edi
    106e:	89 f9                	mov    %edi,%ecx
    1070:	8b 0c 8b             	mov    (%ebx,%ecx,4),%ecx
    1073:	83 c0 01             	add    $0x1,%eax
    1076:	89 82 04 01 00 00    	mov    %eax,0x104(%edx)
    107c:	90                   	nop
    107d:	89 c8                	mov    %ecx,%eax
}
    107f:	5b                   	pop    %ebx
    1080:	5e                   	pop    %esi
    1081:	5f                   	pop    %edi
    1082:	5d                   	pop    %ebp
    1083:	c3                   	ret    

00001084 <enqueue>:

void enqueue(struct binary_semaphore* semaphore)
{
    1084:	55                   	push   %ebp
    1085:	89 e5                	mov    %esp,%ebp
    1087:	57                   	push   %edi
    1088:	56                   	push   %esi
    1089:	53                   	push   %ebx
	semaphore->queue->uthreads[semaphore->queue->head++ % MAX_THREAD] = &ttable[c_thread];
    108a:	8b 45 08             	mov    0x8(%ebp),%eax
    108d:	8b 18                	mov    (%eax),%ebx
    108f:	8b 45 08             	mov    0x8(%ebp),%eax
    1092:	8b 10                	mov    (%eax),%edx
    1094:	8b 82 00 01 00 00    	mov    0x100(%edx),%eax
    109a:	89 c1                	mov    %eax,%ecx
    109c:	c1 f9 1f             	sar    $0x1f,%ecx
    109f:	c1 e9 1a             	shr    $0x1a,%ecx
    10a2:	8d 34 08             	lea    (%eax,%ecx,1),%esi
    10a5:	83 e6 3f             	and    $0x3f,%esi
    10a8:	89 f7                	mov    %esi,%edi
    10aa:	29 cf                	sub    %ecx,%edi
    10ac:	89 f9                	mov    %edi,%ecx
    10ae:	8b 35 0c 17 00 00    	mov    0x170c,%esi
    10b4:	69 f6 18 01 00 00    	imul   $0x118,%esi,%esi
    10ba:	81 c6 20 1b 00 00    	add    $0x1b20,%esi
    10c0:	89 34 8b             	mov    %esi,(%ebx,%ecx,4)
    10c3:	83 c0 01             	add    $0x1,%eax
    10c6:	89 82 00 01 00 00    	mov    %eax,0x100(%edx)
}
    10cc:	5b                   	pop    %ebx
    10cd:	5e                   	pop    %esi
    10ce:	5f                   	pop    %edi
    10cf:	5d                   	pop    %ebp
    10d0:	c3                   	ret    

000010d1 <binary_semaphore_init>:

void binary_semaphore_init(struct binary_semaphore* semaphore, int value)
{
    10d1:	55                   	push   %ebp
    10d2:	89 e5                	mov    %esp,%ebp
    10d4:	83 ec 18             	sub    $0x18,%esp
	semaphore->queue = malloc(sizeof(struct tqueue));
    10d7:	c7 04 24 08 01 00 00 	movl   $0x108,(%esp)
    10de:	e8 76 f9 ff ff       	call   a59 <malloc>
    10e3:	8b 55 08             	mov    0x8(%ebp),%edx
    10e6:	89 02                	mov    %eax,(%edx)
	if (!value)
    10e8:	83 7d 0c 00          	cmpl   $0x0,0xc(%ebp)
    10ec:	75 0c                	jne    10fa <binary_semaphore_init+0x29>
		semaphore->state = S_LOCKED;
    10ee:	8b 45 08             	mov    0x8(%ebp),%eax
    10f1:	c7 40 04 01 00 00 00 	movl   $0x1,0x4(%eax)
    10f8:	eb 0a                	jmp    1104 <binary_semaphore_init+0x33>
	else
		semaphore->state = S_FREE;
    10fa:	8b 45 08             	mov    0x8(%ebp),%eax
    10fd:	c7 40 04 00 00 00 00 	movl   $0x0,0x4(%eax)
}
    1104:	c9                   	leave  
    1105:	c3                   	ret    

00001106 <binary_semaphore_down>:
void binary_semaphore_down(struct binary_semaphore* semaphore)
{
    1106:	55                   	push   %ebp
    1107:	89 e5                	mov    %esp,%ebp
    1109:	83 ec 28             	sub    $0x28,%esp
	//store amount of ticks left and prevent scheduler from switching
	int ticks;
	asm("pusha");
    110c:	60                   	pusha  
	ticks = getTicks();
    110d:	e8 72 f5 ff ff       	call   684 <getTicks>
    1112:	89 45 f4             	mov    %eax,-0xc(%ebp)
	alarm(0);
    1115:	c7 04 24 00 00 00 00 	movl   $0x0,(%esp)
    111c:	e8 5b f5 ff ff       	call   67c <alarm>
	asm("popa");
    1121:	61                   	popa   
	if (semaphore->state == S_LOCKED)
    1122:	8b 45 08             	mov    0x8(%ebp),%eax
    1125:	8b 40 04             	mov    0x4(%eax),%eax
    1128:	83 f8 01             	cmp    $0x1,%eax
    112b:	75 1c                	jne    1149 <binary_semaphore_down+0x43>
	{
		enqueue(semaphore);
    112d:	8b 45 08             	mov    0x8(%ebp),%eax
    1130:	89 04 24             	mov    %eax,(%esp)
    1133:	e8 4c ff ff ff       	call   1084 <enqueue>
		uthread_sleep();
    1138:	e8 f1 fd ff ff       	call   f2e <uthread_sleep>
		alarm(0);
    113d:	c7 04 24 00 00 00 00 	movl   $0x0,(%esp)
    1144:	e8 33 f5 ff ff       	call   67c <alarm>
	}
	semaphore->state = S_LOCKED;
    1149:	8b 45 08             	mov    0x8(%ebp),%eax
    114c:	c7 40 04 01 00 00 00 	movl   $0x1,0x4(%eax)
	//allow the thread to run its remaining time
	alarm(ticks);
    1153:	8b 45 f4             	mov    -0xc(%ebp),%eax
    1156:	89 04 24             	mov    %eax,(%esp)
    1159:	e8 1e f5 ff ff       	call   67c <alarm>

}
    115e:	c9                   	leave  
    115f:	c3                   	ret    

00001160 <binary_semaphore_up>:
void binary_semaphore_up(struct binary_semaphore* semaphore)
{
    1160:	55                   	push   %ebp
    1161:	89 e5                	mov    %esp,%ebp
    1163:	83 ec 28             	sub    $0x28,%esp
	int ticks;
	struct uthread *next;
	asm("pusha");
    1166:	60                   	pusha  
	ticks = getTicks();
    1167:	e8 18 f5 ff ff       	call   684 <getTicks>
    116c:	89 45 f4             	mov    %eax,-0xc(%ebp)
	alarm(0);
    116f:	c7 04 24 00 00 00 00 	movl   $0x0,(%esp)
    1176:	e8 01 f5 ff ff       	call   67c <alarm>
	asm("popa");
    117b:	61                   	popa   


	if ((next = dequeue(semaphore)) == 0)
    117c:	8b 45 08             	mov    0x8(%ebp),%eax
    117f:	89 04 24             	mov    %eax,(%esp)
    1182:	e8 9e fe ff ff       	call   1025 <dequeue>
    1187:	89 45 f0             	mov    %eax,-0x10(%ebp)
    118a:	83 7d f0 00          	cmpl   $0x0,-0x10(%ebp)
    118e:	75 19                	jne    11a9 <binary_semaphore_up+0x49>
	{
		//no thread is waiting. release semaphore and restore alarm
		semaphore->state = S_FREE;
    1190:	8b 45 08             	mov    0x8(%ebp),%eax
    1193:	c7 40 04 00 00 00 00 	movl   $0x0,0x4(%eax)
		asm("pusha");
    119a:	60                   	pusha  
		alarm(ticks);
    119b:	8b 45 f4             	mov    -0xc(%ebp),%eax
    119e:	89 04 24             	mov    %eax,(%esp)
    11a1:	e8 d6 f4 ff ff       	call   67c <alarm>
		asm("popa");
    11a6:	61                   	popa   
    11a7:	eb 0f                	jmp    11b8 <binary_semaphore_up+0x58>
	}
	else
	{
		//threads are waiting. wake up the next thread and yield.
		next->state = T_RUNNABLE;
    11a9:	8b 45 f0             	mov    -0x10(%ebp),%eax
    11ac:	c7 40 10 02 00 00 00 	movl   $0x2,0x10(%eax)
		uthread_yield();
    11b3:	e8 77 fc ff ff       	call   e2f <uthread_yield>
	}
}
    11b8:	c9                   	leave  
    11b9:	c3                   	ret    
